Thursday, September 11, 2008

C# Insert Access sample with Newline constant

string connectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=c:\\sites\\database\\xxxxx.mdb";
OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();
string Strsql = "INSERT INTO CaseInfo(SERVICEID,PROPERTYSTATUS,BANK1NAME,BANK2NAME,TRUSTEENUMBER,TRUSTEESALEDATE,NOD,"
+ "TRAIL,[DATE],HORA,PROCESADORES,TELEMAR,closer)"
+ "VALUES (@SERVICEID,@PROPERTYSTATUS,@BANK1NAME,@BANK2NAME,@TRUSTEENUMBER,@TRUSTEESALEDATE,@NOD,@TRAIL,@DATE,@HORA"
+ "@PROCESADORES,@TELEMAR,@closer)";
OleDbConnection MyConn = new OleDbConnection(connectionString);
myOleDbCommand.CommandText = Strsql;
OleDbCommand cmd = new OleDbCommand(Strsql, MyConn);
cmd.Parameters.AddWithValue("@SERVICEID", DD_Service.SelectedItem.Value);
cmd.Parameters.AddWithValue("@PROPERTYSTATUS", DD_PropertyStatus.SelectedItem.Text);
cmd.Parameters.AddWithValue("@BANK1NAME", txtbank1.Text);
cmd.Parameters.AddWithValue("@BANK2NAME", txtbank2.Text);
cmd.Parameters.AddWithValue("@TRUSTEENUMBER", txtTrusteeSaleNo.Text);
cmd.Parameters.AddWithValue("@TRUSTEESALEDATE", txtTrusteeSaleDate.Text);
cmd.Parameters.AddWithValue("@NOD", txtnod.Text);
cmd.Parameters.AddWithValue("@TRAIL", TxtTrail1.Text);
cmd.Parameters.AddWithValue("@DATE", txtDate.Text);
cmd.Parameters.AddWithValue("@HORA", txtTime.Text);
cmd.Parameters.AddWithValue("@PROCESADORES", DD_PROCESADOR.SelectedItem.Text);
cmd.Parameters.AddWithValue("@TELEMAR", DD_Telemarketing.SelectedItem.Text);
cmd.Parameters.AddWithValue("@closer", DD_Closer.SelectedItem.Text);
MyConn.Open();
cmd.ExecuteNonQuery();
MyConn.Close();

No comments: