我正在将数据插入到数据库中的表中,但一个值需要是整数。如何解决这个问题?这是我的代码到目前为止:我有3个文本框的值可以放入和一个按钮发送它。使用一个整数值将数据插入数据库
private void button1_Click(object sender, EventArgs e)
{
//Maak inert query
string sqlIns = @"INSERT INTO Pizza (Soort, beschrijving, prijs)
VALUES ('" + textBoxSoort.Text.Trim() + "','" + textBoxBescrhijving.Text.Trim() + "', '" + tetBoxPrijs +"') ";
//Maak commando object
OleDbCommand command = new OleDbCommand(sqlIns, Connectie);
try
{
//Open de connectie
Connectie.Open();
//Voer commando uit
command.ExecuteReader();
Connectie.Close();
//Opnieuw vullen DatagridVieuw
vullendgv();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message + ex.StackTrace, "Exception details");
}
finally
{
//Sluiten van de connectie
Connectie.Close();
textBoxSoort.Clear();
textBoxBescrhijving.Clear();
tetBoxPrijs.Clear();
}
}
你得到任何异常或错误信息?你应该总是使用[参数化查询](http://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/)。这种字符串连接对于[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)攻击是开放的。 –
你应该真的使用参数,或者让自己打开sql注入。 – BenR
哪一个是整数? – Alex