必须声明标量变量 "@UserName" 哪里出错了 请大侠们帮忙
SqlCommandcom=newSqlCommand("InsertintoTest(UserName,PassWord,Age,Sex,TrueName)Values...
SqlCommand com = new SqlCommand("Insert into Test(UserName,PassWord,Age,Sex,TrueName) Values(@UserName,@PassWord,@Age,@Sex,@TrueName)", con);
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@UserName",SqlDbType.VarChar,20),
new SqlParameter("@PassWord",SqlDbType.VarChar,20),
new SqlParameter("@Age",SqlDbType.Int),
new SqlParameter("@Sex",SqlDbType.NVarChar,2),
new SqlParameter("@TrueName",SqlDbType.NVarChar,8),
};
param[0].Value = "1";
param[1].Value = "2";
param[2].Value = 3;
param[3].Value = "4";
param[4].Value = "5";
int result = com.ExecuteNonQuery();
if (result > 0)
Console.WriteLine("添加成功");
else
Console.WriteLine("添加失败");
con.Close();
con.Dispose(); 展开
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@UserName",SqlDbType.VarChar,20),
new SqlParameter("@PassWord",SqlDbType.VarChar,20),
new SqlParameter("@Age",SqlDbType.Int),
new SqlParameter("@Sex",SqlDbType.NVarChar,2),
new SqlParameter("@TrueName",SqlDbType.NVarChar,8),
};
param[0].Value = "1";
param[1].Value = "2";
param[2].Value = 3;
param[3].Value = "4";
param[4].Value = "5";
int result = com.ExecuteNonQuery();
if (result > 0)
Console.WriteLine("添加成功");
else
Console.WriteLine("添加失败");
con.Close();
con.Dispose(); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询