embomogrealry
New Member
I have the following class with a function. The function returns true but it does not add data to the database. Can anybody help me?<BR><BR>Thnx.<BR><BR>Public Class DtBase<BR> Dim db As New SqlConnection("server=win2000;database=shailesh;user id=sa;Trusted_connection=yes")<BR><BR> Function AddData(ByVal var1 As String, ByVal var2 As String, ByVal var3 As String, ByVal var4 As String, ByVal var5 As String) As Boolean<BR> Dim DS As New DataSet("AddDt")<BR> Try<BR> db.Open()<BR> Dim mCommand As New SqlCommand("select * from custmast", db)<BR> Dim mAdapter As New SqlDataAdapter(mCommand)<BR> mAdapter.Fill(DS, "CMast")<BR> Dim mrow As DataRow<BR> mrow = DS.Tables("CMast").NewRow()<BR> DS.Tables("CMast").Rows.Add(mrow)<BR> mrow("name") = var1<BR> mrow("address") = var2<BR> mrow("city") = var3<BR> mrow("pin") = var4<BR> mrow("tel") = var5<BR> DS.AcceptChanges()<BR> AddData = http://aspmessageboard.com/archive/index.php/True<BR> Catch myexception As Exception<BR> MsgBox(myexception.ToString())<BR> AddData = False<BR> Finally<BR> DS = Nothing<BR> db.Close()<BR> End TryTry moving the DS.Tables("CMast").Rows.Add(mrow) statement after you populate the columns with data and before the DS.AcceptChanges() statement.<BR><BR>Also, you will have to post the DataSet changes back to the underlying data source with the following statement:<BR><BR>mAdapter.Update(DS, "CMast")<BR>