我正在建立一個網站使用Visual Studio 2013,我堅持讓用戶註冊,一旦提交細節存儲在數據庫中,經理可以登錄並查看所有註冊的帳戶。但我越來越視覺工作室2013獲得關鍵字'表'附近的錯誤語法
Error:System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'Table'. at System.Data.SqlClient.SqlConnection.
BTW表是我存儲註冊帳戶數據的數據庫表的名稱。
任何幫助被佔用!
這是提交按鈕
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;
using System.Configuration;
using System.Configuration;
public partial class Registration :
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString-reg"].ConnectionString); //connects to regstration DB//
conn.Open(); //to open connection to DB
String checkuser = "select count(*) from Table where Name= '"+ nameBox.Text +"'"; // checks wether the name entered is in the database already //
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("User already exists");
}
conn.Close(); //to close connection to DB after executing a query//
}
catch (SqlException Ex)
{
Response.Write("Error:" + Ex.ToString());
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString-reg"].ConnectionString); //connects to regstration DB//
conn.Open(); //to open connection to DB
String insertQuery = "insert into Table (Name, Date of birth, Yoga experience, Health issues, Email address, Telephone number, Password) values (@Name, @dob, @exp, @health, @email, @phone, @password)"; // inserts into table and declares data as variables//
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@Name", nameBox.Text);
com.Parameters.AddWithValue("@dob", Yeardropdown.SelectedItem.ToString());
com.Parameters.AddWithValue("@expe", expBox.Text);
com.Parameters.AddWithValue("@health", healthBox.Text);
com.Parameters.AddWithValue("@email", emailBox.Text);
com.Parameters.AddWithValue("@phone", phoneBox.Text);
com.Parameters.AddWithValue("@passwrd", passwrdBox.Text);
com.ExecuteNonQuery();
Response.Redirect("Manager.aspx");
Response.Write("Thank you, Your registration has been successfull!");
conn.Close();
}
catch (SqlException ex)
{
Response.Write("Error:" + ex.ToString());
}
}
protected void Daydropdown_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
我是相當新的,但我敢肯定,因爲我已經按照沒有失誤的教程,不知道爲什麼會這樣:( –
@ MoAl-azzaniGawi你試過它應該工作的補充[ ]? – Nic