我试图在Windows窗体(C#)上将INSERT INTO插入ACCESS数据库,它没有给我报错。
连接代码:
public Connection()
{
string path = AppDomain.CurrentDomain.BaseDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);
string connString = "provider='Microsoft.jet.OleDb.4.0'; data source='|DataDirectory|\\App_Data\\maple_data.mdb'";
this.con = new OleDbConnection(connString);
}
INSERT INTO代码:
Connection c = new Connection();
c.conOpen();
OleDbCommand cm = new OleDbCommand();
cm.Connection = c.Con;
cm.CommandText = "INSERT INTO bot ([keystroke], [timer], [position]) VALUES (@key, @spamTime, 1)";
cm.Parameters.AddWithValue("@key", Key.Text);
cm.Parameters.AddWithValue("@spamTime", spamTime);
cm.ExecuteNonQuery();
c.conClose();
MessageBox.Show("Key as been added.");
谢谢。
发布于 2018-12-06 10:37:32
请尝试将以下代码连接到您的数据库
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("YOUR CONNECTION STRING");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT`enter code here` Region (RegionID, RegionDescription) VALUES (5, 'NorthWestern')";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
https://stackoverflow.com/questions/-100006229
复制相似问题