Adding Data to Database

Results 1 to 2 of 2

Thread: Adding Data to Database

  1. #1
    Join Date
    Dec 1969

    Default Adding Data to Database

    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;us er 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 = True<BR> Catch myexception As Exception<BR> MsgBox(myexception.ToString())<BR> AddData = False<BR> Finally<BR> DS = Nothing<BR> db.Close()<BR> End Try

  2. #2
    Join Date
    Dec 1969

    Default RE: Adding Data to Database

    Try 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>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts