简体   繁体   English

System.Data.SqlClient.SqlException C#

[英]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.

相关问题 Linq Windows窗体C#System.Data.SqlClient.SqlException - Linq Windows Form C# System.Data.SqlClient.SqlException C#MySQL错误System.Data.SqlClient.SqlException: - C# MySQL error System.Data.SqlClient.SqlException: c#System.Data.SqlClient.SqlException(0x80131904) - c# System.Data.SqlClient.SqlException (0x80131904) System.Data.SqlClient.SqlException:','附近的语法不正确。 C# - System.Data.SqlClient.SqlException: 'Incorrect syntax near ','.' c# System.Data.SqlClient.SqlException - System.Data.SqlClient.SqlException 'System.Data.SqlClient.SqlException' - 'System.Data.SqlClient.SqlException' 在System.Data.dll中发生了C#MS Access数据库连接System.Data.SqlClient.SqlException” - C# MS Access Database Connection System.Data.SqlClient.SqlException' occurred in System.Data.dll 错误System.Data.SqlClient.SqlException:'将数据类型nvarchar转换为数字时出错。 在c#中 - Error System.Data.SqlClient.SqlException: 'Error converting data type nvarchar to numeric.' in c# 尝试从C#代码运行脚本SQL时System.Data.SqlClient.SqlException - System.Data.SqlClient.SqlException when try to run script SQL from C# code C# System.Data.SqlClient.SqlException 无法将值 NULL 插入列 ERROR FOREIGN KEY - C# System.Data.SqlClient.SqlException Cannot insert the value NULL into column ERROR FOREIGN KEY
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM