[英]System.Data.SqlClient.SqlException C#
When I am using cmd.ExecuteNonQuery()
it doesn`t work and shows me the next error: 当我使用
cmd.ExecuteNonQuery()
它不起作用并显示下一个错误:
SqlCommand newUser = new SqlCommand("INSERT INTO [DinoTable] VALUES(@name, @height, @heightscale, @weight, @weightscale, @diet, @status, @locationDis, @dayDis, @monthDis, @yearDis, @yourlocation, @dayborn, @monthborn, @yearborn, @Gender, @yourEmail, @yoname, @lastname, @getmoney); ", c);
newUser.Connection = c;
newUser.Parameters.AddWithValue("@name", (string)Session["Name"]);
newUser.Parameters.AddWithValue("@height", Convert.ToDouble(Session["Height"]));
newUser.Parameters.AddWithValue("@heightscale", (string)Session["HeightScale"]);
newUser.Parameters.AddWithValue("@weight", Convert.ToDouble(Session["Weight"]));
newUser.Parameters.AddWithValue("@weightscale", (string)Session["weightscale"]);
newUser.Parameters.AddWithValue("@diet", (string)Session["diet"]);
newUser.Parameters.AddWithValue("@status", (string)Session["status"]);
newUser.Parameters.AddWithValue("@locationDis", (string)Session["locationDis"]);
newUser.Parameters.AddWithValue("@dayDis", Convert.ToInt32(Session["dayDis"]));
newUser.Parameters.AddWithValue("@monthDis", (string)(Session["monthDis"]));
newUser.Parameters.AddWithValue("@yearDis", Convert.ToInt32(Session["yearDis"]));
newUser.Parameters.AddWithValue("@yourlocation", (string)Session["yourlocation"]);
newUser.Parameters.AddWithValue("@dayborn", Convert.ToInt32(Session["dayborn"]));
newUser.Parameters.AddWithValue("@monthborn", (string)(Session["monthborn"]));
newUser.Parameters.AddWithValue("@yearborn", Convert.ToInt32(Session["yearborn"]));
newUser.Parameters.AddWithValue("@Gender", (string)Session["Gender"]);
newUser.Parameters.AddWithValue("@yourEmail", (string)Session["yourEmail"]);
newUser.Parameters.AddWithValue("@yoname", (string)Session["YourName"]);
newUser.Parameters.AddWithValue("@lastname", (string)Session["YourLastName"]);
newUser.Parameters.AddWithValue("@getmoney", 0);
c.Open()
newUser.ExecuteNonQuery();
c.Close();
the full error: 完整错误:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理
Additional information: The parameterized query '(@name nvarchar(5),@height float,@heightscale nvarchar(4),@weigh' expects the parameter '@monthDis', which was not supplied.
附加信息:参数化查询'(@name nvarchar(5),@ height float,@ heightscale nvarchar(4),@ weigh'需要未提供的参数'@monthDis'。
It seems that the monthDis is a string and the yearDis and dayDis are integers. 看来monthDis是一个字符串,yearDis和dayDis是整数。 Could it be that monthDis is also an integer?
难道monthDis也是整数?
If so, please try changing : 如果是这样,请尝试更改:
newUser.Parameters.AddWithValue("@monthDis", (string)(Session["monthDis"]));
to: 至:
newUser.Parameters.AddWithValue("@monthDis", Convert.ToInt32(Session["monthDis"]));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.