Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
below code working without ERRoR but update value not store in database????

VB
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
Posted
Comments
abbaspirmoradi 25-Aug-13 15:25pm    
oh, you just update datatable.you should update database table with query.

1 solution

VB
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)


VB
For Each Parameter As SqlParameter In com.Parameters
    If Parameter.Value Is Nothing Then
        Parameter.Value = DBNull.Value
    End If
Next
com.ExecuteNonQuery()
 
Share this answer
 
v2
Comments
Parth Akbari 25-Aug-13 15:57pm    
got error "ExecuteNotQuery: Commandtext property has not been initialized"
Parth Akbari 25-Aug-13 16:09pm    
@abbaspirmoradi its solve

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900