Friday, May 8, 2009

Inserting Data to a Database Using DataSets

Inserting Data to a Database Using DataSets: "Imports System.Data.SqlClient
Imports BankMaint.ParastAccountsDataSetTableAdapters
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim parastDS As New ParastAccountsDataSet
Dim bnkRow As ParastAccountsDataSet.BankListRow
Dim bnkListTA As New BankListTableAdapter
bnkRow = parastDS.BankList.NewBankListRow
bnkRow.BankName = txtBnkName.Text
bnkRow.AccountNo = txtAcctNo.Text
bnkRow.Branch = txtBranch.Text
bnkRow.Address = txtAddress.Text
bnkRow.AccountType = txtAcctType.Text
parastDS.BankList.AddBankListRow(bnkRow)

bnkListTA.Update(parastDS.BankList)
End Sub
End Class"

------------------------------------------------------------------More
I do not have MySql and VB.Net installed so here it is just a pseuducode but it must work supposing that you have created an OleDbDataAdapter called da.
Dim dtUsers As New dsData.usersDataTable
da.Fill(dtUsers)
Dim user As dsData.usersRow
Try
user = dtUsers.NewusersRow
user.Name = Me.txtName.Text
user.Email = Me.txtEmail1.Text
dtUsers.Rows.Add(user)
da.Update(dtUsers)
Me.lblAviso.Text = "Added"
Catch ex As Exception
Me.lblAviso.Text = "Error " & ex.Message
End Try

-------------------------------------------------------------------More
Dim dt As DataTable
dt = ds.Tables("Article")
' Insert from the bottom
Dim dr As DataRowdr = dt.NewRow()
dr(0) = 4
dr(1) = "MFC Programming"
dr(2) = "VC++ MFC Library"
dr(3) = 3dr(4) = 3000
dr(5) = DateTime.Parse("8/14/1999")
dt.Rows.Add(dr)
da.Update(ds, "Article")
ds.AcceptChanges()

-----------------------------------------------------------------------More
string connectionString =
“server=(local);Trusted_Connection =yes;database=CCFdb”;
string commandString = “Select * from Agent”;
dataAdapter = new SqlDataAdapter(commandString,connectionString);
sqlCb=new SqlCommandBuilder(dataAdapter)

dataSet = new DataSet();
dataAdapter.Fill(dataSet,”Agent”);

DataRow newRow = dataSet.Tables["Agent"].NewRow();

newRow["a_no"] = txtAgentNo.Text;
newRow["a_name"] = txtAgentName.Text;
newRow["a_add"] = txtAddress.Text;
newRow["tel"] = txtTel.Text;
newRow["reg_no"] = txtRegNo.Text;

dataAdapter.Update(dataSet,”Agent”);
dataSet.AcceptChanges();
Application.DoEvents();

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

More Important Links

Followers