yzgongfs 2019-11-13 15:22 采纳率: 0%
浏览 311
已结题

c# update 数据库始终报连接失败,请指点

private void button6_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = "Server=192.168.0.4;UID=sa;PWD=JStjsy123;DataBase=ufdata_008_2013";
try
{
cnn.Open();
string Sqlstr = @"update temp set temp = 212 where temp = 22";
SqlCommand myCommand = new SqlCommand(Sqlstr);

myCommand.Connection = cnn;

int i = Convert.ToInt32(myCommand.ExecuteNonQuery());

MessageBox.Show("连接成功消息", "消息标题");
}
catch
{
MessageBox.Show("连接失败消息", "消息标题");
}

finally
{

cnn.Close();
}
}

  • 写回答

2条回答 默认 最新

  • Admini$trat0r 新星创作者: 后端开发技术领域 2019-11-13 15:24
    关注

    建议检查下数据库 你这个角色应该有点东西 换一个试试
    还有你这个button能不能好好起名

    评论

报告相同问题?