在Vb.net中更新记录 [英] Update Record in Vb.net

查看:95
本文介绍了在Vb.net中更新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含一些图像字段的表...我添加了一些记录....现在我想更新这些记录....我从datebase表创建了新的数据集并将其拖入表单中作为详细信息。 ..所有字段都来..我无法更新照片字段...请..帮助......还有其他任何方法..我还想更新照片字段....

请帮助...我正在使用sql server .....

I have create one table with some image fields... I have added some records.... now I want to update those records.... I created new dataset from datebase table and drag into a form as detail... all fields comes.. I cannot update photo fields... please.. help... is there any other method.. I also want to update photo fields....
please help... I am using sql server.....

推荐答案

在SQL中,您在数据库中的列类型应该是图像类型,您可以按照下面的代码进行参考和也用于更新去更新查询而不是插入:



In SQL your column type in database should be image type and you can follow below code for reference and also for update go for update query instead of Insert :

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim connection As SqlConnection = Nothing
        Try
            Dim img As FileUpload = CType(imgUpload, FileUpload)
            Dim imgByte As Byte() = Nothing
            If img.HasFile AndAlso Not img.PostedFile Is Nothing Then
                'To create a PostedFile
                Dim File As HttpPostedFile = imgUpload.PostedFile
                'Create byte Array with file len
                imgByte = New Byte(File.ContentLength - 1) {}
                'force the control to load data in array
                File.InputStream.Read(imgByte, 0, File.ContentLength)
            End If
            ' Insert the employee name and image into db
            Dim conn As String = ConfigurationManager.ConnectionStrings("EmployeeConnString").ConnectionString
            connection = New SqlConnection(conn)
 
            connection.Open()
            Dim sql As String = "INSERT INTO EmpDetails(empname,empimg) VALUES(@enm, @eimg) SELECT @@IDENTITY"
            Dim cmd As SqlCommand = New SqlCommand(sql, connection)
            cmd.Parameters.AddWithValue("@enm", txtEName.Text.Trim())
            cmd.Parameters.AddWithValue("@eimg", imgByte)
            Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar())
            lblResult.Text = String.Format("Employee ID is {0}", id)
        Catch
            lblResult.Text = "There was an error"
        Finally
            connection.Close()
        End Try
    End Sub


这篇关于在Vb.net中更新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆