insert出现错误!!!急急急、、、拜托各位了。。。
string sqlSave = "insert into tb_Room(RoomName,RoomJC,RoomBJF,RoomWZ,RoomZT,RoomType,RoomQT,RoomBZ)
Values(" + this.txtRoomName.Text.ToString() + ",//RoomName类型varchar
'" + this.txtRooJC.Text + "',//RoomJC类型char
" + this.txtBJF.Text + ",//RoomBJF类型numberic
'" + this.txtRoomWZ.Text + "',//RoomWZ类型char
'" + this.txtRoomZT.Text+ "',//RoomZT类型char
'" + this.txtRoomType.Text + "',//RoomType类型char
" + this.txtQT.Text.ToString() + ",//RoomQT类型varchar
" + this.txtBZ.Text.ToString() + ") ";//RoomBZ类型varchar
int iSave = DB.infoInsert(sqlSave);//DB是自定义类DB.cs
if (iSave == 1)
{
MessageBox.Show("信息添加成功!!!");
datagridviewBind();
txtBJF.ReadOnly = true;
txtBZ.ReadOnly = true;
txtQT.ReadOnly = true;
txtRooJC.ReadOnly = true;
txtRoomName.ReadOnly = true;
txtRoomType.ReadOnly = true;
txtRoomWZ.ReadOnly = true;
txtRoomZT.ReadOnly = true;
btnCancel.Enabled = false;
btnSave.Enabled = false;
btnQuit.Enabled = true;
btnSearch.Enabled = true;
btnUpdate.Enabled = true;
btnDel.Enabled = true;
btnReset.Enabled = true;
}
if (iSave == 0)
{
MessageBox.Show("信息未能成功添加!!!");
}
DB.cs中的infoInsert(string strInsert)如下
public static int infoInsert(string strInsert)
{
try
{
SqlConnection conInsert = DB.createConnection();
SqlCommand cmdInsert = new SqlCommand(strInsert,conInsert);
cmdInsert.ExecuteReader();
conInsert.Close();
return 1;
}
catch (Exception e1)
{
MessageBox.Show(e1.Message, "数据库没有成功连接!!!");
return 0;
}
}
错误:在此下文中不允许使用大厅。此处只允许使用常量、表达式或变量,不允许使用列明