这是我的错误
Invalid object name 'userdatabase'
这是源错误的代码
enter code here
Line 27:
Line 28: User.Open();
Line 29: xp.ExecuteNonQuery();
Line 30: User.Close();
Line 31:
这是堆栈跟踪
[SqlException (0x80131904): Invalid object name 'userdatabase'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1789270
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5340622
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +275
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1421
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +208
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +163
Default2.Button1_Click(Object sender, EventArgs e) in c:\Users\Calum Barnett\Documents\Visual Studio 2013\WebSites\WebSite3\Default2.aspx.cs:29
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9614758
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
`
这是cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == true)
{
Label1.Text = ("**Registration Succesful");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection User = new SqlConnection("Data Source=TOSHIBA0007\\TESTSERVER;Integrated Security=True");
{
SqlCommand xp = new SqlCommand("Insert into userdatabase(Username, Email, Password)Values(@Username, @Email, @Password)", User);
xp.Parameters.AddWithValue("@Username", InputUsername.Text);
xp.Parameters.AddWithValue("@Email", InputEmail.Text);
xp.Parameters.AddWithValue("@Password", InputPassword.Text);
User.Open();
xp.ExecuteNonQuery();
User.Close();
if (IsPostBack)
{
InputUsername.Text = "";
InputPassword.Text = "";
InputEmail.Text = "";
VerifyPassword.Text = "";
}
}
}
}
感谢任何帮助,因为我是这类错误的初学者。
答案 0 :(得分:0)
表名userdatabase或表名不匹配...
SqlCommand xp = new SqlCommand("Insert into userdatabase(Username, Email,
Password)Values(@Username, @Email, @Password)", User);
xp.Parameters.AddWithValue("@Username", InputUsername.Text);
xp.Parameters.AddWithValue("@Email", InputEmail.Text);
xp.Parameters.AddWithValue("@Password", InputPassword.Text);