private void btOk_Click(object sender, EventArgs e)
{
String strSQL;
if (m_bInsert)
{
if (txtNum.Text == "")
{
MessageBox.Show("期号不能为空");
return;
}
strSQL = "INSERT INTO 表1 VALUES('" + txtNum.Text + "','" + comRed1st.Text + ",'" + comRed2nd.Text + "','"
+ comRed3rd.Text + "','" + comRed4th.Text+ "','"
+ comRed5th.Text + "','" + comRed6th.Text + "','" + comBlue.Text + "') ";
}
OleDbConnection oleDbConn = null;
try
{
oleDbConn = new OleDbConnection(Properties.Resources.ConnectionString);
oleDbConn.Open();
OleDbCommand oleDbComm = new OleDbCommand(strSQL, oleDbConn);
oleDbComm.ExecuteNonQuery();
if (m_bInsert)
{
MessageBox.Show("插入成功!");
}
}
catch (OleDbException)
{
if (m_bInsert)
{
MessageBox.Show("插入失败!");
}
}
finally
{
oleDbConn.Close();
}
Dispose();
}错误提示我说 使用了未赋职的局部变量"strSQL"小弟第一次提问没多少分
{
String strSQL;
if (m_bInsert)
{
if (txtNum.Text == "")
{
MessageBox.Show("期号不能为空");
return;
}
strSQL = "INSERT INTO 表1 VALUES('" + txtNum.Text + "','" + comRed1st.Text + ",'" + comRed2nd.Text + "','"
+ comRed3rd.Text + "','" + comRed4th.Text+ "','"
+ comRed5th.Text + "','" + comRed6th.Text + "','" + comBlue.Text + "') ";
}
OleDbConnection oleDbConn = null;
try
{
oleDbConn = new OleDbConnection(Properties.Resources.ConnectionString);
oleDbConn.Open();
OleDbCommand oleDbComm = new OleDbCommand(strSQL, oleDbConn);
oleDbComm.ExecuteNonQuery();
if (m_bInsert)
{
MessageBox.Show("插入成功!");
}
}
catch (OleDbException)
{
if (m_bInsert)
{
MessageBox.Show("插入失败!");
}
}
finally
{
oleDbConn.Close();
}
Dispose();
}错误提示我说 使用了未赋职的局部变量"strSQL"小弟第一次提问没多少分
这是一个字符串,在声明的时候,应先有一个初始值。
在没有赋值前是不能进行下面的赋值。
strSQL = "INSERT INTO 表1 VALUES('" + txtNum.Text + "','" + comRed1st.Text + ",'" + comRed2nd.Text + "','"
+ comRed3rd.Text + "','" + comRed4th.Text+ "','"
+ comRed5th.Text + "','" + comRed6th.Text + "','" + comBlue.Text + "') ";
、
可以在声明时候给一个空值;