DataAdapter + DataRow + Inserting a record

A

A.J

###########################################################################


private void btnAdd_Click(object sender, System.EventArgs e)
{
OleDbConnection con = new OleDbConnection(str);
con.Open();
string qry = "select * from t_contact";
OleDbDataAdapter da = new OleDbDataAdapter(qry,con);
DataSet ds = new DataSet();
da.Fill(ds,"t_contact");
DataTable dt = new DataTable();
dt = ds.Tables["t_contact"];
DataRow dr ;
dr = dt.NewRow();
dr["FirstName"] = txtFirstName.Text;
dr["LastName"] = txtLastName.Text;
dr["E-Mail"] = txtEMail.Text;
dr["PhoneNumber"] = txtPhoneNumber.Text;
ds.Tables["t_contact"].Rows.Add(dr);
textBox2.Text = ds.GetXml();
da.Update(ds,"t_contact");
}
###########################################################################
__________________________________________________________
here e-mail is the primary key.Unable to insert record in the database.
__________________________________________________________
The error coming is :
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO
statement.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at Contact_new.Form1.btnAdd_Click(Object sender, EventArgs e) in
c:\documents and settings\administrator\my documents\visual studio
projects\projects\contact_new\form1.cs:line 234
 
T

Terry Burns

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO
statement.

Where is the Insert string ? Please post it !

--
Terry Burns
http://TrainingOn.net
A.J said:
###########################################################################


private void btnAdd_Click(object sender, System.EventArgs e)
{
OleDbConnection con = new OleDbConnection(str);
con.Open();
string qry = "select * from t_contact";
OleDbDataAdapter da = new OleDbDataAdapter(qry,con);
DataSet ds = new DataSet();
da.Fill(ds,"t_contact");
DataTable dt = new DataTable();
dt = ds.Tables["t_contact"];
DataRow dr ;
dr = dt.NewRow();
dr["FirstName"] = txtFirstName.Text;
dr["LastName"] = txtLastName.Text;
dr["E-Mail"] = txtEMail.Text;
dr["PhoneNumber"] = txtPhoneNumber.Text;
ds.Tables["t_contact"].Rows.Add(dr);
textBox2.Text = ds.GetXml();
da.Update(ds,"t_contact");
}
###########################################################################
__________________________________________________________
here e-mail is the primary key.Unable to insert record in the database.
__________________________________________________________
The error coming is :
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO
statement.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at Contact_new.Form1.btnAdd_Click(Object sender, EventArgs e) in
c:\documents and settings\administrator\my documents\visual studio
projects\projects\contact_new\form1.cs:line 234
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top