I have written such a simple code in vb.net
I have used data adapter command and dataset to pass data in database
this is my code
Code:Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click If Mode = "New" Then sql = "select * from donorentry" cmd = New SqlClient.SqlCommand(sql, cn) Dim dt As DataTable dset.Clear() dadap.SelectCommand = cmd 'dadap.Fill(dset) dadap.Fill(dset, "donorentry") dt = dset.Tables("donorentry") ro = dt.NewRow 'dset.Clear() SetRows() dt.Rows.Add(ro) ' ==================== Error on this statement ================ 'error is 'Update requires a valid InsertCommand when passed DataRow collection with new rows. dadap.Update(dset, "donorentry") ElseIf Mode = "Edit" Then ro.BeginEdit() SetRows() ro.EndEdit() End If End Sub
Code:Private Sub SetRows() 'initialization of record into ro (a data row) ' ro is declared globally ro.Item("did") = txtDID.Text ro.Item("entrydate") = dtEntryDate.Value ro.Item("fname") = txtFirstName.Text ro.Item("lname") = txtLastName.Text ro.Item("sname") = txtSurName.Text ' first time tried this method of initializing it was also not working then changed into above format. 'ro!hadd1 = txtHadd1.Text 'ro!hadd2 = txtHadd2.Text 'ro!hcity = cmbCity.Text 'ro!hstate = cmbHstate.Text 'ro!hcountry = cmbHCountry.Text 'ro!hpin = txtHPincode.Text End Sub
I am trying from three days but I couldn't touch the solution.
Every where on net I found this method to insert record. I cant understand where there is silly mistake in this code.
Please help me




Reply With Quote