Public Shared Function ExecuteNonQuery(ByVal sql As String, ByVal parameters As SqlParameter()) As Integerĭim constr As String = ConfigurationManager.ConnectionStrings("ConnectionString"). Using sda As SqlDataAdapter = New SqlDataAdapter(cmd) Using cmd As SqlCommand = New SqlCommand(sql, con) Using con As SqlConnection = New SqlConnection(constr) Public Shared Function SelectFromDatabase(ByVal sql As String, ByVal parameters As SqlParameter()) As DataTableĭim constr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString ![]() Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)ĭim filePath As String = ĭim filename As String = Path.GetFileName(filePath)ĭim ext As String = Path.GetExtension(filename)ĭim size As Integer = ĭim fs As Stream = ĭim br As BinaryReader = New BinaryReader(fs)ĭim bytes As Byte() = br.ReadBytes(CType(fs.Length, Int32))ĭim sql As String = "insert into CarImgTbl(Name, Contyp,Size, Data)" & " values parameters As SqlParameter() = ĭim dt As DataTable = SelectFromDatabase(sql, parameters)ĭisplayImage.ImageUrl = "data:image/jpg base64," & Convert.ToBase64String(CType(dt.Rows(0)("Data"), Byte()))ĭisplayImage.AlternateText = "The Image has been found"ĭisplayImage.AlternateText = "The Image does not exist in DataBase"ĭisplayImage.AlternateText = "The input seems not an id " ![]() If e.Row.RowType = DataControlRowType.DataRow Thenĭim dr As DataRowView = CType(e.Row.DataItem, DataRowView)ĭim imageUrl As String = "data:image/jpg base64," & Convert.ToBase64String(CType(dr("Data"), Byte()))ĭim image1 As Image = CType(e.Row.FindControl("Image1"), Image) Protected Sub CarImgGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Reader.readAsDataURL(input.files) // convert to base64 stringĬode behind: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Loadĭim sql As String = "SELECT * FROM CarImgTbl"ĬarImgGridView.DataSource = SelectFromDatabase(sql, Nothing) I constructed a demo to show how the gridview works with database and this simple demo also shows how to retrieve an image with an identifier. You could refer to below codes using VB.Net with webforms.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |