我是新来的SQL和视觉工作室等,但我已经改变了一些不允许我登录到我的应用程序。每当我按下登录按钮我得到这个错误SQL“来自'的关键字附近的语法错误'。”
不正确的语法“从”
这里就是源可以是关键字附近;
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;
namespace RockPaperApp
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["New"] != null)
{
Response.Redirect("/Game.aspx");
}
}
protected void RegButton_Press(object sender, EventArgs e)
{
Response.Redirect("/Register.aspx");
}
protected void LogButton_Press(object sender, EventArgs e)
{
string username = UsernameLogTxt.Text;
try
{
string conn = ConfigurationManager.ConnectionStrings["UserConS"].ToString();
string CommandText = "pword from data [email protected]";
using (SqlConnection connection = new SqlConnection(conn.ToString()))
using (SqlCommand command = new SqlCommand(CommandText, connection))
{
command.Parameters.AddWithValue("@username", username);
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string realpass = reader[0].ToString();
if (realpass != PasswordLogTxt.Text)
{
Response.Write("<span style='color:red'>A Wrong Username of Password has been entered.</span>");
}
else
{
Session["New"] = UsernameLogTxt.Text;
Response.Redirect("/Game.aspx");
}
}
if (!reader.HasRows)
{
Response.Write("No such username exists.");
}
}
connection.Close();
}
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Register.aspx");
}
}
}
尽管对于这个问题可能并不重要:当提问SQL问题时**总是**添加对应于你的DBMS的标签('postgresql','oracle' ,'sql-server',...)。 ** SQL **是一种查询语言,而不是DBMS产品。 –