Private Sub sbloadgrd()
Dim x As String = "select unqid, imgTitle, imgTh from Image_Gallery_AYS"
Dim con As New SqlConnection(Dal.conMain)
Dim dt As New DataTable
dt = Dal.GettDS(x).Tables(0)
GridView1.DataSource = dt
GridView1.DataBind()
我在gridview
中绑定标题和图像,下面是我如何在数据库中保存图像:
Dim obj As New clsAddImageGallery
obj.imgTitle = txtTitle.Text
obj.imgDesc = txtDecs.Text
Dim imgth1 As String = fileuploadimg.PostedFile.FileName
Dim str1 As String() = imgth1.Split(".")
Dim strex1 As String = str1(1)
obj.img = "~/uploads/" + g.ToString() + "." + strex1
Dim imgth3 As String = fileuploadthumb.PostedFile.FileName
Dim str3 As String() = imgth1.Split(".")
Dim strex3 As String = str3(1)
obj.imgTh = "~/uploads/" + g.ToString() + "." + strex3
我收到img url
而不是img
。
答案 0 :(得分:1)
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)
If FileUpload1.PostedFile IsNot Nothing Then
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
'Save files to disk
FileUpload1.SaveAs(Server.MapPath("images/" & FileName))
'Add Entry to DataBase
Dim strConnString As [String] = System.Configuration. _
ConfigurationManager.ConnectionStrings("conString"). _
ConnectionString
Dim con As New SqlConnection(strConnString)
Dim strQuery As String = "insert into tblFiles (FileName, FilePath)" _
& " values(@FileName, @FilePath)"
Dim cmd As New SqlCommand(strQuery)
cmd.Parameters.AddWithValue("@FileName", FileName)
cmd.Parameters.AddWithValue("@FilePath", "images/" & FileName)
cmd.CommandType = CommandType.Text
cmd.Connection = con
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.Message)
Finally
con.Close()
con.Dispose()
End Try
End If
End Sub