您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在''btechstudent_academics'附近使用正确的语法设置Tenth = @ Tenth Where Regd_no = @ Regd_no' [英] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''btechstudent_academics' set Tenth=@Tenth Where Regd_no=@Regd_no'

查看:133
本文介绍了您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在''btechstudent_academics'附近使用正确的语法设置Tenth = @ Tenth Where Regd_no = @ Regd_no'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新MYSQL数据库...出现错误表示

您的SQL语法出错;请查看与您的MySQL服务器版本对应的手册以获得正确的语法在''btechstudent_academics'附近使用设置Tenth = @ Tenth Where Regd_no = @ Regd_no'在第1行..请建议如何纠正这一个......

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 MySql.Data.MySqlClient;
使用 System.IO;

public partial class BtechSrtudentUpdate:System.Web.UI.Page
{
MySqlConnection conn1 = new MySqlConnection( Server = localhost; Database = test; Uid = root; Pwd = 1234);

string r = ;
受保护 void Page_Load( object sender,EventArgs e)
{

TextBoxtRegd.Text = Request.QueryString [ REGD];

TextBoxTenth.Text = Request.QueryString [ 第十];


}
受保护 void Button1_Click(< span class =code-keyword> object
sender,EventArgs e)
{
string Regd_no;
Double 第十;
Regd_no = TextBoxtRegd.Text;
Tenth = Convert.ToDouble(TextBoxTenth.Text);

conn1.Open();
string sql2 = 更新'btechstudent_academics' set Tenth = @ Tenth + Where Regd_no = @ Regd_no;;
MySqlCommand cmd2 = new MySqlCommand(sql2,conn1);
MySqlParameter param = new MySqlParameter( @第十个,MySqlDbType。 Double );
param.Value =第十;
cmd2.Parameters.Add(param);
MySqlParameter param1 = new MySqlParameter( @ Regd_no,MySqlDbType.VarChar, 10 );
param.Value = Regd_no;
cmd2.Parameters.Add(param1);

尝试
{
Response.Write( HI);
cmd2.ExecuteNonQuery();

Response.Write( HI2);
}
catch (例外x)
{Label1.Text = + x.Message; }
最后
{
conn1.Close();
}

}
受保护 void TextBox1_TextChanged( object sender,EventArgs e)
{

}
protected void TextBoxBacklog_TextChanged( object sender,EventArgs e)
{

}
受保护 void TextBoxTenth_TextChanged(对象发​​件人,EventArgs e)
{

}
protected void TextBox9_TextChanged( object sender,EventArgs e)
{

}
}

解决方案

问题出在你的查询中,表的名称是用singl转义的引号(')。

这告诉MySQL有一个字符串值,因此它不会将其识别为表名。

将它们更改为反引号( `):

  string  sql2 =   UPDATE`btechstudent_academics` set Tenth = @ Tenth +  其中Regd_no = @ Regd_no;; 



或将它们遗漏:

 < span class =code-keyword> string  sql2 =   UPDATE btechstudent_academics set Tenth = @ Tenth +  其中Regd_no = @ Regd_no;; 


添加更多解释。你基本上有三个选择。由于您的表名不是保留字,因此无需转义它。因此,以下内容应该足够了:

  string  sql2 =   UPDATE btechstudent_academics set Tenth = @ Tenth Where Regd_no = @ Regd_no;; 



如果它是一个保留字,你需要逃避它。为此你有两种技巧。反击总是有效,查询看起来像

  string  sql2 =   UPDATE`btechstudent_academics` set Tenth = @ Tenth Where Regd_no = @ Regd_no;; 



另一方面,您已设置 ANSI_QUOTES [ ^ ] on你可以使用这样的引号

  string  sql2 =    UPDATE \btechstudent_academics \set Tenth = @ Tenth Where Regd_no = @ Regd_no;; 





  string  sql2 =  @  更新 btechst udent_academics   set Tenth = @ Tenth Where Regd_no = @ Regd_no;; 



有关详细信息,请参阅文档架构对象名称 [ ^ ]






我认为问题可能在更新声明中。

试试这个:

  string  sql2 =   UPDATE'btechstudent_academics'set Tenth = + @Tenth +   Where Regd_no = @ Regd_no; 


I AM TRYING TO UPDATE AN MYSQL DATABASE...THE ERROR APPEARS SAYING
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''btechstudent_academics' set Tenth=@Tenth Where Regd_no=@Regd_no' at line 1"..PLEASE SUGGEST HOW TO CORRECT THIS ONE...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.IO;

public partial class BtechSrtudentUpdate : System.Web.UI.Page
{
    MySqlConnection conn1 = new MySqlConnection("Server=localhost;Database=test;Uid=root;Pwd=1234");
    
    string r=" ";
    protected void Page_Load(object sender, EventArgs e)
    {
        
        TextBoxtRegd.Text = Request.QueryString["regd"];
        
        TextBoxTenth.Text = Request.QueryString["Tenth"];
       
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Regd_no;
		Double Tenth;
        Regd_no = TextBoxtRegd.Text;
        Tenth = Convert.ToDouble(TextBoxTenth.Text);
         
        conn1.Open();
        string sql2 = "UPDATE 'btechstudent_academics' set Tenth=@Tenth" + " Where Regd_no=@Regd_no;";
        MySqlCommand cmd2 = new MySqlCommand(sql2, conn1);
        MySqlParameter param = new MySqlParameter("@Tenth",MySqlDbType.Double );
        param.Value = Tenth;
        cmd2.Parameters.Add(param );
        MySqlParameter param1 = new MySqlParameter("@Regd_no", MySqlDbType.VarChar,10);
        param.Value = Regd_no ;
        cmd2.Parameters.Add(param1);
     
        try
        {
            Response.Write("HI");
            cmd2.ExecuteNonQuery();

            Response.Write("HI2");
        }
        catch (Exception x)
        { Label1.Text = " " + x.Message; }
        finally
        {
            conn1.Close();
        }
        
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBoxBacklog_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBoxTenth_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox9_TextChanged(object sender, EventArgs e)
    {

    }
}

解决方案

The problem is in your query, the name of the table is escaped with single quotes (').
This tells MySQL that there is a string value, so it doesn't recognize it as a table name.
Either change them to backticks (`):

string sql2 = "UPDATE `btechstudent_academics` set Tenth=@Tenth" + " Where Regd_no=@Regd_no;";


or leave them out:

string sql2 = "UPDATE btechstudent_academics set Tenth=@Tenth" + " Where Regd_no=@Regd_no;";


To add a bit more explanations. You basically have three options. Since your table name isn't a reserved word, there's no need to escape it. Because of this the following should suffice:

string sql2 = "UPDATE btechstudent_academics set Tenth=@Tenth Where Regd_no=@Regd_no;";


If it would be a reserved word you would need to escape it. For this you have two techniques. Backticking would always work and the query would look like

string sql2 = "UPDATE `btechstudent_academics` set Tenth=@Tenth Where Regd_no=@Regd_no;";


On the other hand it you have set ANSI_QUOTES[^] on you can use quotation marks like this

string sql2 = "UPDATE \"btechstudent_academics\" set Tenth=@Tenth Where Regd_no=@Regd_no;";


or

string sql2 = @"UPDATE "btechstudent_academics" set Tenth=@Tenth Where Regd_no=@Regd_no;";


For more info, please refer to documentation Schema Object Names[^]


Hi,

I think the problem could be in update statement.
Try this:

string sql2 = "UPDATE 'btechstudent_academics' set Tenth=" + @Tenth + " Where Regd_no=@Regd_no";


这篇关于您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在''btechstudent_academics'附近使用正确的语法设置Tenth = @ Tenth Where Regd_no = @ Regd_no'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆