SqlCommand
using(SqlConnection conn=new SqlConnection("server=127.0.0.1;database=shui"+";uid="+txt_uid.Text.Trim()+";pwd="+txt_pwd.Text.Trim())

...{
conn.Open();
using(SqlCommand cmd = conn.CreateCommand())

...{
cmd.CommandText = string.Format("UPDATE yhb SET zs = '{1}' WHERE zcm='{0}'",
txt_zcm.Text, txt_zc.Text); // 此处放置你的 SQL 语句
cmd.ExecuteNonQuery();
}
}
SqlParameter
SqlConnection conn = new SqlConnection("server=127.0.0.1;database=shui" + ";uid=" + txt_uid.Text.Trim() + ";pwd=" + txt_pwd.Text.Trim());
conn.Open();
SqlCommand STcmd = new SqlCommand(conn);
STcmd.CommandText = "update yhb set zs = @txt_zs where zcm = @zcm";
SqlParameter p1 = new SqlParameter("@txt_zs");
p1.Value = txt_zs.Text;
SqlParameter p2 = new SqlParameter("@zcm");
p2.Value = "100001";
STcmd.Parameters.Add(p1);
STcmd.Parameters.Add(p2);
cmd.ExecuteNonQuery();
SqlCommand.Parameters.AddWithValue
SqlConnection conn=new SqlConnection("server=127.0.0.1;database=shui"+";uid="+txt_uid.Text.Trim()+";pwd="+txt_pwd.Text.Trim());
SqlCommand STcmd = new SqlCommand("update yhb set zs = @zs where zcm = '100001'", conn);
STcmd.Parameters.AddWithValue("@zs",txt_zs.Text);
conn.Open();
STcmd.ExecuteNonQuery();
conn.Close();
StringBuilder
StringBuilder strBuilder = new StringBuilder(2000);
strBuilder.AppendFormat("UPDATE yhb SET zs = '{1}' WHERE zcm='{0}'",
txt_zcm.Text, txt_zc.Text);
System.String strSql = strBuilder.toString();
































