string yzConnStr = "server=breeze-53c40694; userid=sa; password=sa; database=pxfz";
---》string yzConnStr = "server=breeze-53c40694; database=pxfz; uid=sa; pwd=sa;";
---》string yzConnStr = "server=breeze-53c40694; database=pxfz; uid=sa; pwd=sa;";
如果是字符型,需要加上'号
string SqlInsertStr1 = "INSERT INTO px (aaa,bbb) "+" Values ('"+TextBox1.Text+"','"+TextBox2.Text+"')";
是字符型,加了‘还是不行
{
try
{
string yzConnStr = "Data Source=breeze-53c40694;Initial Catalog=pxfz;User Id=sa;Password=sa;" ;
SqlConnection cnn = new SqlConnection(yzConnStr);
cnn.Open();
string SqlInsertStr1 = "INSERT INTO px (aaa,bbb) "+" Values ('"+TextBox1.Text+"','"+TextBox2.Text+"')";
SqlCommand insert_cmd = new SqlCommand(SqlInsertStr1,cnn);
insert_cmd.ExecuteNoQuery();
cnn.Close();
}
catch (Exception ex)
{
MesssageBox.Show(ex.ToString());
}
}
看看有什么问题!
后面的语句
看看你的 command的
cmd0.ExecuteReader();
cmd0.ExecuteNonQuery();等,贴上来看看
SqlConnection cnn = new SqlConnection(yzConnStr);
cnn.Open();
string SqlInsertStr1 = "INSERT INTO px (aaa,bbb) "+" Values ('"+TextBox1.Text+"','"+TextBox2.Text+"')";
SqlCommand insert_cmd = new SqlCommand(SqlInsertStr1,cnn);
insert_cmd.ExecuteNoQuery();
cnn.Close();这样应该可以了