Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新sql查询_C#_Sql_Sql Update - Fatal编程技术网

C# 更新sql查询

C# 更新sql查询,c#,sql,sql-update,C#,Sql,Sql Update,嗨,我正在尝试将点从windows从更新到数据库,但我不确定如何从变量“totalPoints”中获取信息,以便从数据库插入“points”字段 using (OleDbConnection conn = new OleDbConnection(strCon)) { String sqlPoints = "UPDATE points FROM customer WHERE [customerID]=" + txtCustomerID

嗨,我正在尝试将点从windows从更新到数据库,但我不确定如何从变量“totalPoints”中获取信息,以便从数据库插入“points”字段

using (OleDbConnection conn = new OleDbConnection(strCon))
        {
            String sqlPoints = "UPDATE points FROM customer WHERE [customerID]="
            + txtCustomerID.Text;
            conn.Open();


            conn.Close();
        }

谢谢你的帮助

首先,您应该使用参数化查询-这容易受到SQL注入的影响

请看这里:

要回答您的问题,您需要查看
OleDbCommand
ExecuteNonQuery

public void InsertRow(string connectionString, string insertSQL)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        // The insertSQL string contains a SQL statement that
        // inserts a new row in the source table.
        OleDbCommand command = new OleDbCommand(insertSQL);

        // Set the Connection to the new OleDbConnection.
        command.Connection = connection;

        // Open the connection and execute the insert command.
        try
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}

此外,您可能需要重新查看SQL——不确定您要完成什么。如果您使用的是SQL Server,语法应该类似于
UPDATE TABLE SET FIELD=VALUE,其中FIELD=VALUE


祝您好运。

首先,您应该使用参数化查询-这很容易受到SQL注入的影响

请看这里:

要回答您的问题,您需要查看
OleDbCommand
ExecuteNonQuery

public void InsertRow(string connectionString, string insertSQL)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        // The insertSQL string contains a SQL statement that
        // inserts a new row in the source table.
        OleDbCommand command = new OleDbCommand(insertSQL);

        // Set the Connection to the new OleDbConnection.
        command.Connection = connection;

        // Open the connection and execute the insert command.
        try
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}

此外,您可能需要重新查看SQL——不确定您要完成什么。如果您使用的是SQL Server,语法应该类似于
UPDATE TABLE SET FIELD=VALUE,其中FIELD=VALUE


祝你好运。

好的,谢谢。我会将其更改为参数化查询!如何使其更新表中全部读取的字段(例如从0到25)?这就是您的意思:更新客户设置点=25,其中customerid=1确定感谢我将其更改为参数化查询!如何使其更新表中全部读取的字段(例如从0到25)?这就是您的意思:更新客户设置点=25,其中customerid=1