System.Data.SqlClient.SqlException C#

时间:2016-05-13 09:41:34

标签: c# sql asp.net

当我使用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();

完整错误:

  

类型' System.Data.SqlClient.SqlException'的异常发生在   System.Data.dll但未在用户代码中处理

     

附加信息:参数化查询'(@ name   nvarchar(5),@ height float,@ heightscale nvarchar(4),@ weigh'期待   参数' @ monthDis',未提供。

1 个答案:

答案 0 :(得分:0)

似乎monthDis是一个字符串,yearDis和dayDis是整数。 可能是那个月是一个整数?

如果有,请尝试更改:

newUser.Parameters.AddWithValue("@monthDis", (string)(Session["monthDis"]));

为:

newUser.Parameters.AddWithValue("@monthDis", Convert.ToInt32(Session["monthDis"]));