golnouri
جمعه 27 اسفند 1389, 15:41 عصر
دوستان برای بخش ContactUs وب سایتم از data base access استفاده کردم که وقتی اجرا می کنم هیچ اروری دریافت نمی کنم اما هیچ نوشته ای رو تو دیتا بیس ثبت نمیکنه!
کدهایی که نوشتم و براتون میذارم دلیلش و بهم بگید.
DataSet ds = new DataSet();
string strSql;
string strCon;
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbConnection Con = new OleDbConnection();
DataRow newRow;
OleDbCommandBuilder cb = new OleDbCommandBuilder();
strCon = "Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = |DataDirectory|/Contact.mdb";
strSql = "SELECT * FROM Contact";
Con = new OleDbConnection(strCon);
Con.Open();
da = new OleDbDataAdapter(strSql, Con);
da.Fill(ds, "Contact");
newRow = ds.Tables["Contact"].NewRow();
newRow["Name"] = TextBox1.Text;
newRow["Email"] = TextBox2.Text;
newRow["Mobile"] = TextBox3.Text;
newRow["Subject"] = TextBox4.Text;
newRow["Text"] = TextBox5.Text;
cb = new OleDbCommandBuilder(da);
da.InsertCommand = cb.GetInsertCommand();
da.Update(ds, "Contact");
Con.Close();
کدهایی که نوشتم و براتون میذارم دلیلش و بهم بگید.
DataSet ds = new DataSet();
string strSql;
string strCon;
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbConnection Con = new OleDbConnection();
DataRow newRow;
OleDbCommandBuilder cb = new OleDbCommandBuilder();
strCon = "Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = |DataDirectory|/Contact.mdb";
strSql = "SELECT * FROM Contact";
Con = new OleDbConnection(strCon);
Con.Open();
da = new OleDbDataAdapter(strSql, Con);
da.Fill(ds, "Contact");
newRow = ds.Tables["Contact"].NewRow();
newRow["Name"] = TextBox1.Text;
newRow["Email"] = TextBox2.Text;
newRow["Mobile"] = TextBox3.Text;
newRow["Subject"] = TextBox4.Text;
newRow["Text"] = TextBox5.Text;
cb = new OleDbCommandBuilder(da);
da.InsertCommand = cb.GetInsertCommand();
da.Update(ds, "Contact");
Con.Close();