C#更新数据返回用判断更新成功
publicstaticstringAddXX(stringCustomerName,stringCustomerTel,stringCustomerAdd,string...
public static string AddXX(string CustomerName, string CustomerTel, string CustomerAdd, string CustomerBank, string CustomerBankNo, string CustomerEmail, string CustomerQQ, string CustomerURL)
{
string Sql = "update Customer,RegUser set CustomerName=@name,CustomerTel=@in,CustomerAdd=@add,CustomerBank=@bank,CustomerBankNo=@bankbo,CustomerEmail=@email,CustomerQQ=@qq,CustomerURL=@url where Customer.CustomerID=RegUser.CustomerID and RegUser.UserName =@tel";
if (SqlCon.State != ConnectionState.Open)
{
SqlCon.Open();
}
SqlCommand cmd = new SqlCommand(Sql, SqlCon);
cmd.Parameters.Add("@name", CustomerName);
cmd.Parameters.Add("@in", CustomerTel);
cmd.Parameters.Add("@add", CustomerAdd);
cmd.Parameters.Add("@bank", CustomerBank);
cmd.Parameters.Add("@bankbo", CustomerBankNo);
cmd.Parameters.Add("@email", CustomerEmail);
cmd.Parameters.Add("@qq", CustomerQQ);
cmd.Parameters.Add("@url", CustomerURL);
cmd.Parameters.Add("@tel", HttpContext.Current.Session["UserTel"].ToString());
int i =(int)cmd.ExecuteNonQuery();
if (i>0)
{
return Shared.ToJson.Succ();
}
else
{
return Shared.ToJson.Fail();
}
} 展开
{
string Sql = "update Customer,RegUser set CustomerName=@name,CustomerTel=@in,CustomerAdd=@add,CustomerBank=@bank,CustomerBankNo=@bankbo,CustomerEmail=@email,CustomerQQ=@qq,CustomerURL=@url where Customer.CustomerID=RegUser.CustomerID and RegUser.UserName =@tel";
if (SqlCon.State != ConnectionState.Open)
{
SqlCon.Open();
}
SqlCommand cmd = new SqlCommand(Sql, SqlCon);
cmd.Parameters.Add("@name", CustomerName);
cmd.Parameters.Add("@in", CustomerTel);
cmd.Parameters.Add("@add", CustomerAdd);
cmd.Parameters.Add("@bank", CustomerBank);
cmd.Parameters.Add("@bankbo", CustomerBankNo);
cmd.Parameters.Add("@email", CustomerEmail);
cmd.Parameters.Add("@qq", CustomerQQ);
cmd.Parameters.Add("@url", CustomerURL);
cmd.Parameters.Add("@tel", HttpContext.Current.Session["UserTel"].ToString());
int i =(int)cmd.ExecuteNonQuery();
if (i>0)
{
return Shared.ToJson.Succ();
}
else
{
return Shared.ToJson.Fail();
}
} 展开
2个回答
展开全部
SQL语句不对,将
string Sql = "update Customer,RegUser set CustomerName=@name,CustomerTel=@in,CustomerAdd=@add,CustomerBank=@bank,CustomerBankNo=@bankbo,CustomerEmail=@email,CustomerQQ=@qq,CustomerURL=@url where Customer.CustomerID=RegUser.CustomerID and RegUser.UserName =@tel";改为
string Sql = "update Customer set CustomerName=@name,CustomerTel=@in,CustomerAdd=@add,CustomerBank=@bank,CustomerBankNo=@bankbo,CustomerEmail=@email,CustomerQQ=@qq,CustomerURL=@url FROM Customer join RegUser where Customer.CustomerID=RegUser.CustomerID and RegUser.UserName =@tel";
string Sql = "update Customer,RegUser set CustomerName=@name,CustomerTel=@in,CustomerAdd=@add,CustomerBank=@bank,CustomerBankNo=@bankbo,CustomerEmail=@email,CustomerQQ=@qq,CustomerURL=@url where Customer.CustomerID=RegUser.CustomerID and RegUser.UserName =@tel";改为
string Sql = "update Customer set CustomerName=@name,CustomerTel=@in,CustomerAdd=@add,CustomerBank=@bank,CustomerBankNo=@bankbo,CustomerEmail=@email,CustomerQQ=@qq,CustomerURL=@url FROM Customer join RegUser where Customer.CustomerID=RegUser.CustomerID and RegUser.UserName =@tel";
追问
提示:
关键字 'where' 附近有语法错误。
追答
下面这个应该可以。上面那个语句加上别名也可以的。
string Sql = "update Customer set CustomerName=@name,CustomerTel=@in,CustomerAdd=@add,CustomerBank=@bank,CustomerBankNo=@bankbo,CustomerEmail=@email,CustomerQQ=@qq,CustomerURL=@url where Customer.CustomerID=(Select CustomerID FROM RegUser WHERE UserName =@tel)";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询