C#插入sql server错误... [英] C# Insert into sql server error...
本文介绍了C#插入sql server错误...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void cmdAdd_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection();
myConnection.Open();
try
{
myConnection.ConnectionString = "Data Source=ACER-LAPTOP\a2006; Database=AED_MOBILE_0; Initial Catalog=db_stuRegisterPay; Integrated Security=SSPI";
}
catch
{
Console.WriteLine(e.ToString());
}
SqlCommand myCommand = new SqlCommand("INSERT INTO TestInfo(TestIC, TestName, TestPhone) " + "VALUES('" + txtIC.Text + "','" + txtName.Text + "','" +
txtPhone.Text + "')", myConnection);
try
{
myCommand.ExecuteNonQuery();
BCE.Application.AppMessage.ShowMessage("Pass!!!");
}
catch
{
BCE.Application.AppMessage.ShowMessage(myCommand.CommandText );
}
myConnection.Close();
}
推荐答案
private void cmdAdd_Click(object sender, EventArgs e)
{
String connStr= "Data Source=ACER-LAPTOP\a2006; Database=AED_MOBILE_0; Initial Catalog=db_stuRegisterPay; Integrated Security=SSPI";
SqlConnection myConnection = new SqlConnection(connStr);
myConnection.Open();
SqlCommand myCommand = new SqlCommand("INSERT INTO TestInfo(TestIC, TestName, TestPhone) " + "VALUES('" + txtIC.Text + "','" + txtName.Text + "','" +
txtPhone.Text + "')", myConnection);
try
{
myCommand.ExecuteNonQuery();
BCE.Application.AppMessage.ShowMessage("Pass!!!");
}
catch
{
BCE.Application.AppMessage.ShowMessage(myCommand.CommandText );
}
myConnection.Close();
}
如果不行,请解释你的错误。
if not working then explain your error.
这篇关于C#插入sql server错误...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文