ACCESS database on the SQL server and execute SQL statements
I. Description of the problem
Why write this article, because ... by three self-proclaimed novice within a week to ask questions in this regard, so tidy program, you want to make newbies learn
Second, the method
1. MS SQL Server 01 // === MS SQL server database for the next SQL syntax ===
02
03 // Transact-SQL statements
04 String strSQL = "INSERT INTO TableName ( student number, student name, student class, student phone) VALUES ( '49125001', ' John', ' cowherd', '028 825 252') ";
05 // strSQL String =" DELETE the FROM TableName the WHERE student number = '49,125,001' ";
06 // String = strSQL" UPDATE TableName SET student class = 'regular classes' WHERE student name = 'John' ";
07 // strSQL string =" the SELECT * the FROM TableName ";
08
09 // the SqlConnection (string): the connection string that contains the specified string when the new instance initialization SqlConnection class.
System.Data.SqlClient.SqlConnection sqlConn = 10
. 11 new new System.Data.SqlClient.SqlConnection ( "the Data the Source = localhost; the User Id = SA; Password = SA;
SqlConn.Open 14 ();
15
16 // SqlCommand (String, the SqlConnection): a new instance using the query text and SqlConnection, SqlCommand class initialization.
System.Data.SqlClient.SqlCommand sqlcmd =. 17
18 is new new System.Data.SqlClient.SqlCommand (strSQL, sqlConn);
. 19
20 is performed for the connection // Transact-SQL statements.
SqlCmd.ExecuteNonQuery 21 is ();
22 is
23 is // close the connection.
24 sqlConn.Close ();
2. ACCESS
=== 01 // under Access database to SQL syntax ===02
03 // Transact-SQL statements
04 String strSQL = "INSERT INTO TableName ( student number, student name, student class, student phone) VALUES ( '49125001' , 'John', 'cowherd', '028 825 252') ";
05 // strSQL String =" DELETE the FROM TableName the WHERE student number = '49,125,001' ";
06 // strSQL String =" UPDATE TableName the SET student class = ' regular classes' WHERE student name = 'John' ";
07 // strSQL string =" the SELECT * the FROM TableName ";
08
09 // OleDbConnection (string): when the connection string contains the specified string, the implementation of new OleDbConnection class initialization individual.
System.Data.OleDb.OleDbConnection oleConn = 10
. 11 System.Data.OleDb.OleDbConnection new new ( "Provider = Microsoft.Jet.OLEDB.4.0; the Data db.mdb the Source =");
12
13 // open the database connection.
14 oleConn.Open ();
15
16 // OleDbCommand (String, OleDbConnection): a new instance of text and OleDbConnection, OleDbCommand class is used to initialize the query.
System.Data.OleDb.OleDbCommand oleCmd =. 17
18 is new new System.Data.OleDb.OleDbCommand (strSQL, oleConn);
. 19
20 is performed for the connection // Transact-SQL statements.
OleCmd.ExecuteNonQuery 21 is ();
22 is
23 is // close the connection.
24 oleConn.Close ();
Original: Large column [C #] on the SQL server database and execute SQL statements ACCESS