Hi,
I am really new to VB.net & trying this first time. I want to update my huge database using SQLdataadapter. I am using following codes which gives me no error but does not make any changes either to my database. Please help.....
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
SqlDataAdapter1.UpdateCommand.CommandText = "UPDATE dbo.MKTest SET ID = @ID, Lname = @Lname, Fname = @Fname WHERE (ID = @Origi" & _
"nal_ID) AND (Fname = @Original_Fname OR @Original_Fname IS NULL AND Fname IS NUL" & _
"L) AND (Lname = @Original_Lname OR @Original_Lname IS NULL AND Lname IS NULL); S" & _
"ELECT ID, Lname, Fname FROM dbo.MKTest WHERE (ID = @ID)"
SqlUpdateCommand1.Connection = SqlConnection1
SqlDataAdapter1.UpdateCommand.Connection.Open()
Dim myParm As SqlParameter = SqlDataAdapter1.UpdateCommand.Parameters.Add("@Original_ID", SqlDbType.Decimal, 9, "ID")
myParm.SourceColumn = "ID"
myParm.SourceVersion = DataRowVersion.Original
Dim myParm1 As SqlParameter = SqlDataAdapter1.UpdateCommand.Parameters.Add("@Original_Fname", SqlDbType.VarChar, 10, "Fname")
myParm1.SourceColumn = "Fname"
myParm1.Value = Trim(TextBox2.Text.ToString)
myParm1.SourceVersion = DataRowVersion.Current
Dim myParm2 As SqlParameter = SqlDataAdapter1.UpdateCommand.Parameters.Add("@Original_Lname", SqlDbType.VarChar, 10, "Lname")
myParm2.SourceColumn = "Lname"
myParm2.Value = Trim(TextBox3.Text.ToString)
myParm2.SourceVersion = DataRowVersion.Current
SqlDataAdapter1.Update(DataSet11, "MKTest")
Catch ex As Exception
Errormessages.Text = ex.ToString
End Try
SqlDataAdapter1.UpdateCommand.Connection.Close()
Errormessages.Text = "Update Done"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Errormessages.Text = " "
If Trim(TxtEmpBugtNum.Text) = "" Then
Errormessages.Text = "Please enter the Employee/Budget Authorization Number; you want to change"
Exit Sub
End If
SqlDataAdapter1.SelectCommand.Parameters.Clear()
SqlDataAdapter1.SelectCommand.Parameters.Add("@Param1", System.Data.SqlDbType.Decimal, 9, "ID").Value = TxtEmpBugtNum.Text
Try
SqlDataAdapter1.Fill(DataSet11)
Catch
Errormessages.Text = "Record not found"
Exit Sub
End Try
If DataSet11.MKTest.Rows.Count = 0 Then
Errormessages.Text = "Record not found"
Exit Sub
Else
TextBox2.Text = DataSet11.MKTest(0).Fname
TextBox3.Text = DataSet11.MKTest(0).Lname
End If
Thanks in advance,
mcharaia
I am really new to VB.net & trying this first time. I want to update my huge database using SQLdataadapter. I am using following codes which gives me no error but does not make any changes either to my database. Please help.....
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
SqlDataAdapter1.UpdateCommand.CommandText = "UPDATE dbo.MKTest SET ID = @ID, Lname = @Lname, Fname = @Fname WHERE (ID = @Origi" & _
"nal_ID) AND (Fname = @Original_Fname OR @Original_Fname IS NULL AND Fname IS NUL" & _
"L) AND (Lname = @Original_Lname OR @Original_Lname IS NULL AND Lname IS NULL); S" & _
"ELECT ID, Lname, Fname FROM dbo.MKTest WHERE (ID = @ID)"
SqlUpdateCommand1.Connection = SqlConnection1
SqlDataAdapter1.UpdateCommand.Connection.Open()
Dim myParm As SqlParameter = SqlDataAdapter1.UpdateCommand.Parameters.Add("@Original_ID", SqlDbType.Decimal, 9, "ID")
myParm.SourceColumn = "ID"
myParm.SourceVersion = DataRowVersion.Original
Dim myParm1 As SqlParameter = SqlDataAdapter1.UpdateCommand.Parameters.Add("@Original_Fname", SqlDbType.VarChar, 10, "Fname")
myParm1.SourceColumn = "Fname"
myParm1.Value = Trim(TextBox2.Text.ToString)
myParm1.SourceVersion = DataRowVersion.Current
Dim myParm2 As SqlParameter = SqlDataAdapter1.UpdateCommand.Parameters.Add("@Original_Lname", SqlDbType.VarChar, 10, "Lname")
myParm2.SourceColumn = "Lname"
myParm2.Value = Trim(TextBox3.Text.ToString)
myParm2.SourceVersion = DataRowVersion.Current
SqlDataAdapter1.Update(DataSet11, "MKTest")
Catch ex As Exception
Errormessages.Text = ex.ToString
End Try
SqlDataAdapter1.UpdateCommand.Connection.Close()
Errormessages.Text = "Update Done"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Errormessages.Text = " "
If Trim(TxtEmpBugtNum.Text) = "" Then
Errormessages.Text = "Please enter the Employee/Budget Authorization Number; you want to change"
Exit Sub
End If
SqlDataAdapter1.SelectCommand.Parameters.Clear()
SqlDataAdapter1.SelectCommand.Parameters.Add("@Param1", System.Data.SqlDbType.Decimal, 9, "ID").Value = TxtEmpBugtNum.Text
Try
SqlDataAdapter1.Fill(DataSet11)
Catch
Errormessages.Text = "Record not found"
Exit Sub
End Try
If DataSet11.MKTest.Rows.Count = 0 Then
Errormessages.Text = "Record not found"
Exit Sub
Else
TextBox2.Text = DataSet11.MKTest(0).Fname
TextBox3.Text = DataSet11.MKTest(0).Lname
End If
Thanks in advance,
mcharaia