ExecuteNonQuery: Connection 属性尚未初始化
namespacegood{publicpartialclassForm3:Form{SqlConnectionconn;SqlCommandcmd;SqlDataAda...
namespace good
{
public partial class Form3 : Form
{
SqlConnection conn;
SqlCommand cmd;
SqlDataAdapter ada;
DataSet ds;
private void Form3_Load(object sender, EventArgs e)
{
string ConnectionString = "Data Source=SASE;Initial Catalog=PAS;User ID=KEY;Password=PS";
conn = new SqlConnection(ConnectionString);
conn.Open();
if (conn.State == ConnectionState.Open)
;
else
MessageBox.Show("数据库连接失败,请重试");
}
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text.Trim().ToString();
cmd = new SqlCommand("INSERT INTO usertable(username) VALUES"+name, conn);
cmd.ExecuteNonQuery();
}
}
最后一句会报错说属性尚未初始化,为什么啊T T 展开
{
public partial class Form3 : Form
{
SqlConnection conn;
SqlCommand cmd;
SqlDataAdapter ada;
DataSet ds;
private void Form3_Load(object sender, EventArgs e)
{
string ConnectionString = "Data Source=SASE;Initial Catalog=PAS;User ID=KEY;Password=PS";
conn = new SqlConnection(ConnectionString);
conn.Open();
if (conn.State == ConnectionState.Open)
;
else
MessageBox.Show("数据库连接失败,请重试");
}
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text.Trim().ToString();
cmd = new SqlCommand("INSERT INTO usertable(username) VALUES"+name, conn);
cmd.ExecuteNonQuery();
}
}
最后一句会报错说属性尚未初始化,为什么啊T T 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询