使用vb.net更新数据库中的值 [英] updating value in database using vb.net

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

问题描述

以下代码在没有ERRoR的情况下工作,但更新值没有存储在数据库中????



below code working without ERRoR but update value not store in database????

Try

            da = New SqlDataAdapter("SELECT * FROM studentdetails where student_id= @id", myConn)
            da.SelectCommand.Parameters.AddWithValue("@id", txt_id.Text)
            da.Fill(dset, "studentdetails")

            If dset.Tables("studentdetails").Rows(0)("student_id") = Convert.ToInt32(txt_id.Text) Then
                dset.Tables("studentdetails").Rows(0)("student_name") = txt_name.Text
                dset.Tables("studentdetails").Rows(0)("student_branch") = txt_branch.Text
                dset.Tables("studentdetails").Rows(0)("student_class") = txt_class.Text
                MsgBox("Update Complete")
            Else
                MsgBox("Record not found")
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        Finally

            myConn.Close()
        End Try

推荐答案

Dim sqlcommand As String = "UPDATE studentdetails  SET student_name=@txt_name , student_branch=@txt_branch ,student_class=@txt_class "
Dim com As New SqlCommand(sqlcommand, myConn)
com.Parameters.AddWithValue("@txt_name", txt_name.Text)
com.Parameters.AddWithValue("@txt_branch", txt_branch.Text)
com.Parameters.AddWithValue("@txt_class", txt_class.Text)







For Each Parameter As SqlParameter In com.Parameters
    If Parameter.Value Is Nothing Then
        Parameter.Value = DBNull.Value
    End If
Next
com.ExecuteNonQuery()


这篇关于使用vb.net更新数据库中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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