网页更新语句不会在SQL Server中更新

时间:2018-12-09 21:18:23

标签: c# sql-server visual-studio

我的更新语句起作用,但不幸的是,它实际上并未更新SQL Server中的行。当我检查SQL Server时,该行与创建“配置文件”时的行相同。请让我知道,除了我的更新声明以外,是否还需要其他信息。

这是我的代码:

// Update statement
SqlConnection MyConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["F18_kslchaneconnectionstringLOGIN"].ConnectionString);

string updatestatement = "UPDATE dbo.userprof SET firstu = '"+TextBox1+"', lastu='"+TextBox1+ "', emailu='" + TextBox2 + "',phonenum='" + TextBox3 + "',orgname='" + TextBox4 + "',titleuser='" + TextBox5 + "',deptuser='" + TextBox6 + "', password='" + TextBox7 + "');";

SqlCommand mysqlupdate = new SqlCommand(updatestatement, MyConnection);

// cn.Open();
// string sql = "UPDATE main SET s_name='" + TextBox1.Text + "',inst_code='" + DropDownList1.SelectedItem.Value.ToString() + "',ms_oms='" + Label7.Text + "',elligiblity='" + Label12.Text + "',Board='" + DropDownList5.SelectedItem.Value.ToString() + "',percentage='" + float.Parse(TextBox4.Text) + "',amount='" + Label10.Text + "' WHERE elg_id = " + DropDownList4.SelectedItem.Value + "";

// OleDbCommand cmd = new OleDbCommand(sql, cn);
// cmd.ExecuteNonQuery();
// cmd.Dispose();
// cn.Close();

// mysqlupdate.Parameters.AddWithValue("@firstu", TextBox1.Text);
// mysqlupdate.Parameters.AddWithValue("@lastu", TextBox1.Text);
// mysqlupdate.Parameters.AddWithValue("@emailu", TextBox2.Text);
// mysqlupdate.Parameters.AddWithValue("@phonenum", TextBox3.Text);
// mysqlupdate.Parameters.AddWithValue("@orgname", TextBox4.Text);
// mysqlupdate.Parameters.AddWithValue("@titleuser", TextBox5.Text);
// mysqlupdate.Parameters.AddWithValue("@deptuser", TextBox6.Text);
// mysqlupdate.Parameters.AddWithValue("@password", TextBox7.Text);

try
{
    MyConnection.Open();
    // mysqlupdate.ExecuteNonQuery();
    // mysqlupdate.Dispose();

    Label1.Text = "User has been updated!";
}
catch (Exception myexception)
{
    Label1.Text = myexception.Message;
    MyConnection.Close();
}

1 个答案:

答案 0 :(得分:0)

创建query BlogPostArchive1 { allMarkdownRemark( limit: 10 sort: { order: DESC, fields: [frontmatter___date] } ) { edges { node { excerpt frontmatter { title slug date(formatString: "MMMM DD, YYYY") } } } } } 是不够的-您还需要执行它:

SqlCommand