【发布时间】:2016-04-05 00:34:09
【问题描述】:
我完全是编程新手。我的程序有问题,我想做的是创建一个注册页面,以便用户可以注册,它会保存到 SQL 数据库中,但是我收到一个错误,我不知道这意味着什么,我将整个粘贴错误信息很抱歉,如果它不具体。如果可能的话,请用简单的话给我解释一下,谢谢。
这是我的代码:
protected void registerBtn_Click(object sender, EventArgs e)
{
String conString = @"Data Source=sql-server;Initial Catalog=wa310;Integrated Security=True";
SqlConnection myConnection = new SqlConnection(conString);
string cmd = "INSERT INTO Student( First_Name, Surname, User_ID, Password) VALUES ( '" + fNameTxt.Text + "' , '" + sNameTxt.Text + "','" + userIdTxt.Text + "' ,'" + passwordTxt.Text + "')";
SqlCommand myCommand = new SqlCommand(cmd, myConnection);
try
{
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
Label1.Text = "You have successfully registered";
}
catch (Exception ex)
{
Label1.Text = "Exception in DBHandler" + ex;
}
finally
{
myConnection.Close();
}
}
这是我得到的错误,再次对长错误消息表示抱歉:
DBHandlerSystem.Data.SqlClient.SqlException (0x80131904) 中的异常: 字符串或二进制数据将被截断。该声明已 终止。在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常, Boolean breakConnection, Action
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler、SqlDataReader 数据流、 BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean & dataReady) 在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(字符串 方法名,布尔异步,Int32 超时,布尔异步写入)在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 完成,字符串方法名,布尔型 sendToPipe,Int32 超时, 布尔 asyncWrite) 在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 在 OnlineExamCW.Register.registerBtn_Click(Object sender, EventArgs e) in f:\COMP1551 - 应用程序和 Web 开发\OnlineExamCW\OnlineExamCW\Register.aspx.cs:第 31 行 ClientConnectionId:e08ebbe3-d4be-4a76-a64d-14aadb6e9d4c
请告诉我这个错误是什么意思。非常感谢。
【问题讨论】:
-
错误消息告诉您输入值中的某些内容太长而无法存储在指定列中。请显示当前数据库中的 Student 表的架构。
标签: c# asp.net sql-server message