如何在关键字“user”附近解决此错误不正确的语法 [英] How can I solve this error incorrect syntax near the keyword 'user'
本文介绍了如何在关键字“user”附近解决此错误不正确的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用.NET和C#开发Web应用程序。我无法解决这个问题,请帮帮我。
I am developing a web application using .NET and C#. I am unable to fix this problem please help me.
protected void Button1_Click(object sender, EventArgs e)
{
string et = signupemail.Text;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string checkser = "select count (*) from [user] where email ='" + et + "'";
SqlCommand cmd1 = new SqlCommand(checkser, conn);
int temp1 = Convert.ToInt32(cmd1.ExecuteScalar().ToString());
conn.Close();
if (temp1 == 1)
{
Response.Write("already exist");
}
else
{
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
int x=0;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con1;
con1.Open();
cmd.CommandText = "insert into user(name,email,password,sponserid,upline1,upline2,upline3,upline4,wallet,phonenumber) Values(@name,@email,@password,@sponserid,@upline1,@upline2,@upline3,@upline4,@wallet,@phonenumber)";
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = name1.Text;
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = signupemail.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar).Value =pass2.Text ;
cmd.Parameters.Add("@sponserid", SqlDbType.VarChar).Value = "csvf";
cmd.Parameters.Add("@upline1", SqlDbType.VarChar).Value = "bhghg";
cmd.Parameters.Add("@upline2", SqlDbType.VarChar).Value = "bhghg";
cmd.Parameters.Add("@upline3", SqlDbType.VarChar).Value = "bhghg";
cmd.Parameters.Add("@upline4", SqlDbType.VarChar).Value = "bhghg";
cmd.Parameters.Add("@wallet", SqlDbType.VarChar).Value = x;
cmd.Parameters.Add("@phonenumber", SqlDbType.VarChar).Value = phone1.Text;
try
{
cmd.ExecuteNonQuery();
con1.Close();
Response.Redirect("profile.aspx");
}
catch (Exception ex)
{
string msg = "Insert Error:";
msg += ex.Message;
Label1.Text = ex.Message;
}
}
}
我尝试了什么:
i am new编码请帮助我
What I have tried:
i am new to coding please help me
推荐答案
每次使用时都需要使用方括号USER(或更好地将表名更改为users),它是一个SQL关键字。所以改变:
You need brackets round USER (or better change teh table name to "users") every time you use it, it's an SQL keyword. So change:
cmd.CommandText = "insert into user(name,email,password,sponserid,upline1,upline2,upline3,upline4,wallet,phonenumber) Values(@name,@email,@password,@sponserid,@upline1,@upline2,@upline3,@upline4,@wallet,@phonenumber)";
收件人:
To:
cmd.CommandText = "insert into [user](name,[email],[password],sponserid,upline1,upline2,upline3,upline4,wallet,phonenumber) Values(@name,@email,@password,@sponserid,@upline1,@upline2,@upline3,@upline4,@wallet,@phonenumber)";
我讨厌降价![/ edit]
[edit]I hate markdown![/edit]
这篇关于如何在关键字“user”附近解决此错误不正确的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文