2 Replies - 5956 Views - Last Post: 02 February 2011 - 05:06 PM Rate Topic: -----

#1 cutedevils  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-April 09

i think i made a wrong syntax in getting the path of the image

Posted 31 January 2011 - 05:36 PM

hi every one, i am tring to upload images to a asp.net web form using the visual studio 2010
i made all fine, but i think there is a mistake in getting the url of the image, so that i can display in grid view
i made this code and its working to insert the data to the DB , but still the image is not appearing in the grid view
Imports System
Imports System.Data
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.Image
Imports System.Web.UI.WebControls.ImageMap


Public Class products
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim connectionstring As String = "provider=Microsoft.ACE.OLEDB.12.0 ; DATA SOURCE=C:\Users\Allouch\Documents\Visual Studio 2010\Projects\khadra-glass\khadra-glass\App_Data\khadra.accdb "
        Dim conn As New OleDb.OleDbConnection(connectionstring)
        Dim query As String = " INSERT INTO [products] ([prod-id],[price],[prod-name])values ('" & Trim(productidtxtbx.Text) & "' , '" & Trim(pricetxtbx.Text) & "' , '" & Trim(productnametxtbx.Text) & "' );"
        Dim cmd As New OleDb.OleDbCommand(query, conn)
        'Dim filename As String
        'Dim filepath As String


        Dim pth As String = Server.MapPath(imgupload.FileName)
        Dim item As String = "C:\Users\Allouch\Documents\Visual Studio 2010\Projects\khadra-glass\khadra-glass\images\" & User.ToString
        Dim item1 As String = "images\" & User.ToString
        Dim item2 As String = Trim(item1 + "\" + imgupload.FileName.ToString())
        Dim item3 As String = Trim(pth + "\" + imgupload.FileName.ToString())

        conn.Open()
        Dim ccmd As New OleDb.OleDbCommand
        ccmd.Connection = conn
        Dim TheDataReader As OleDb.OleDbDataReader = cmd.ExecuteReader
        TheDataReader.Read()
        ccmd.CommandText = " INSERT INTO [products] ([prod-id],[price],[prod-name], [image])values ('" & Trim(productidtxtbx.Text) & "' , '" & Trim(pricetxtbx.Text) & "' , '" & Trim(productnametxtbx.Text) & "', '" & Trim(item3) & " ' );"
        ccmd.ExecuteNonQuery()



        If imgupload.FileName = Nothing Then
            MsgBox("browse image to continue")
        Else



            If imgupload.FileName.EndsWith(".jpg") Or imgupload.FileName.EndsWith(".gif") Or imgupload.FileName.EndsWith(".jpeg") Or imgupload.FileName.EndsWith(".JPEG") Or imgupload.FileName.EndsWith(".GIF") Or imgupload.FileName.EndsWith(".JPG") Then


                If Not My.Computer.FileSystem.DirectoryExists(item) Then

                    MkDir(item)
                    imgupload.SaveAs(item3)
                Else
                    If Not My.Computer.FileSystem.FileExists(item2) Then
                        imgupload.SaveAs(item3)
                    End If
                End If
            End If

        End If


        MsgBox("uploaded sucessfuly")
        Response.Redirect("products.aspx")



        Response.ContentType = TheDataReader("MIMEType").ToString()
        Response.BinaryWrite(TheDataReader("ImageData"))


        TheDataReader.Close()

        conn.Close()

    End Sub
End Class
----------------------
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="products.aspx.vb" Inherits="khadra_glass.products" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Label ID="Label1" runat="server" Text="Product ID"></asp:Label>
        <asp:TextBox ID="productidtxtbx" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Product Name"></asp:Label>
        <asp:TextBox ID="productnametxtbx" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label3" runat="server" Text="Price"></asp:Label>
        <asp:TextBox ID="pricetxtbx" runat="server"></asp:TextBox>
        <br />
        <asp:FileUpload ID="imgupload" runat="server" />
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="submit " Width="126px" 
            style="height: 26px" />
    
        <br />
        <br />
        
        <br />
    
    </div>
    
  
<div>
    

<asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" 
              DataSourceID="AccessDataSource1" Width="399px" AllowPaging="True" 
        AllowSorting="True" BackColor="White" BorderColor="#CCCCCC" 
        BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" 
        GridLines="Horizontal">
<Columns>
    <asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="prod-id" HeaderText="prod-id" 
                
                               SortExpression="prod-id" />
<asp:BoundField DataField="prod-name" HeaderText="prod-name" 
        SortExpression="prod-name" />
<asp:BoundField DataField="price" HeaderText="price" 
                               SortExpression="price" />
                             <asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="100px" Width="100px"
           ImageUrl='<%#  Eval("image")%>' />
</ItemTemplate>
</asp:TemplateField>

    
</Columns>
    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F7F7F7" />
    <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
    <SortedDescendingCellStyle BackColor="#E5E5E5" />
    <SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
   
        DataFile="~/App_Data/khadra.accdb" SelectCommand="SELECT * FROM [products]">
    </asp:AccessDataSource>


    
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="AccessDataSource2">
    </asp:Repeater>
    <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
     
        DataFile="~/App_Data/khadra.accdb" SelectCommand="SELECT * FROM [products]">
    </asp:AccessDataSource>


    
    </div>
    </form>

</body>
</html> 

thanks in advance :)

Is This A Good Question/Topic? 0
  • +

Replies To: i think i made a wrong syntax in getting the path of the image

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: i think i made a wrong syntax in getting the path of the image

Posted 31 January 2011 - 11:18 PM

See if this article helps.
Was This Post Helpful? 0
  • +
  • -

#3 cutedevils  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-April 09

Re: i think i made a wrong syntax in getting the path of the image

Posted 02 February 2011 - 05:06 PM

View PostNakor, on 31 January 2011 - 11:18 PM, said:

See if this article helps.

thx .. im cheking on :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1