How to form data in to database tables using oledb providers

Posted by Srinivasulu.enugu under ASP.NET on 7/1/2011 | Points: 10 | Views : 1465 | Status : [Member] | Replies : 3
Hi friends...

I have some problem here...

I have 1 web form. in that web form empid .empname ,salary .address fields and one save button is there . when ever click the button , i want save values in the DB emp table. for that

i wrote code in button click event code behind page.......

protected void Button1_Click(object sender, EventArgs e)
{
con = new OleDbConnection("Data Source=.;Initial Catalog=emp;Integrated Security=True");
con.Open();
cmd = new OleDbCommand ("INSERT INTO emp values ( '"+TextBox1 .Text+ "','"+TextBox2 .Text+ "','"+TextBox3 .Text+"','"+TextBox4 .Text +"'",con);
cmd.ExecuteReader();
con.Close();

}

but error is ...................

System.ArgumentException was unhandled by user code
Message="An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'."
Source="System.Data"

Srinivasulu Enugu


Responses

Posted by: Neha-kapoor on: 7/1/2011 [Member] Starter | Points: 25

Up
0
Down
hallo
which provider you use for,coze if you use native client then genrate error
only support sql.
pls paste the full code behind page here

thanks

Srinivasulu.enugu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vilasgite080 on: 7/2/2011 [Member] Starter | Points: 25

Up
0
Down
hi its ConnectionString problem
please refer : http://www.c-sharpcorner.com/UploadFile/mimrantaj/Database102102008130743PM/Database1.aspx?ArticleID=cc1f522e-19e6-4667-ab5f-16ad7cde497b#ReadAndPostComment
-------------
If this reply hepls your post.then "MARK AS ANSWER"!

Srinivasulu.enugu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/3/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
hi Srinivasulu.enugu

your code lacks few things, i have rewritten it and it should look like this


protected void Button1_Click(object sender, EventArgs e)

{

OleDbConnection con = new OleDbConnection("Data Source=.;Initial Catalog=emp;Integrated Security=True");
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText ="INSERT INTO emp values ( '" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "'";
OleDbDataReader reader;
try
{
con.Open();

reader = cmd.ExecuteReader();
//Do whatever with a Reader
//while (reader.Read())
//{
// lbFound.Items.Add(reader["FirstName"].ToString() +
// " " + rdr["LastName"].ToString());
//}
}
catch (Exception ex)
{

}
finally
{
con.Close();
}
}
}


hope this helps



Thank you for posting at Dotnetfunda
[Administrator]

Srinivasulu.enugu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response