string jizuname1 = textBox4.Text;
string zhuanziname1 = textBox5.Text;
double zhuanzi11 = Convert.ToInt32(textBox101.Text);
double zhuanzi12 = Convert.ToInt32(textBox111.Text);
double zhuanzi13 = Convert.ToInt32(textBox121.Text);
string sql = " INSERT INTO 转子基本参数 values('" + jizuname1 + "','" + zhuanziname1 + "'," + zhuanzi11 + "," + zhuanzi12 + "," + zhuanzi13 + ")";
loaddata.instance.ExecuteSQL(sql);
为什么每次都插不到数据库呢
在access中直接执行这句话,可以插入数据, INSERT INTO 转子基本参数 values('aa','s',1,2,3)
“转子基本参数表” 中五个字段分别是 文本,文本,数字,数字,数字
public int ExecuteSQL(string SQLString)//执行SQL语句
{
string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + @"\data\wang.accdb";
using (OleDbConnection connection = new OleDbConnection(strConnection))
{
using (OleDbCommand cmd = new OleDbCommand(SQLString, connection))
{
OleDbTransaction tx = null;
try
{//通过连接启动事务
connection.Open();//一个连接对象只能调用一次
tx = connection.BeginTransaction();
cmd.Transaction = tx;//一个连接对象可以调用多次
int rows = cmd.ExecuteNonQuery();//执行数据库 非查询类操作、
tx.Commit();
connection.Close();
return rows;
}
catch (System.Data.OleDb.OleDbException e)
{
tx.Rollback();
connection.Close();
throw e;
}
}
}
}
public DataTable QuerySQL(string sql)
{
DataSet dset = new DataSet();
try
{
//1、建立连接 Microsoft.Jet.OLEDB.4.0
string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + @"\data\wang.accdb";
OleDbConnection odcConnection = new OleDbConnection(strConn);
//2、打开连接
odcConnection.Open();
//建立SQL查询
OleDbCommand odCommand = odcConnection.CreateCommand();
//3、输入查询语句
odCommand.CommandText =sql;
OleDbDataAdapter ODbda = new OleDbDataAdapter();
ODbda.SelectCommand = odCommand;
ODbda.Fill(dset);
odcConnection.Close();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message, "数据库连接有问题!");
}
// return dset.Tables[0];
if (dset != null)
return dset.Tables[0];
else
return null;
}
以上是数据库信息,数据库应该是连上了,别的地方也取过数据,成功了