且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我的代码不起作用?

更新时间:2023-02-03 19:38:45

首先,当问一个问题不工作时,我们不会告诉我们这个问题。提供详细信息,包括您正在尝试的内容,您期望的内容以及错误。



接下来您的更新声明可能是错误的。您正在尝试将一堆字段更新为新值,其中这些字段等于新值,因此它当然不起作用。你也有混合文本和参数化的SQL。不要那样做。坚持使用参数。



此外,你需要在更新后重新调整你的研磨,而不仅仅是刷新。


Hi No errors in code its runs and Done
but its not update my data in data base

con.ConnectionString = con_str
        con.Open()
        com.Connection = con
        com.CommandText = "UPDATE kharabi SET natije=@natije where (kharabi_sal='" & TextBox10.Text & "' and kharabi_mah='" & TextBox6.Text & "' and kharabi_rooz='" & TextBox5.Text & "' and shomare='" & TextBox1.Text & "' and bookht='" & TextBox2.Text & "' and method='" & ComboBox1.Text & "' and moshkel='" & TextBox3.Text & "' and source='" & ComboBox2.Text & "' and markaz='" & ComboBox3.Text & "') "
       
        com.Parameters.AddWithValue("natije", TextBox4.Text)

        com.ExecuteNonQuery()
        MsgBox("انجام شد")
        com.Dispose()
        con.Close()
        DataGridView1.Refresh()
        Form3_Load(1, e)

First, when asking a question "not working" tells us nothing about the problem. Provide details including what you are trying, what you expect, and errors.

Next your update statement is probably wrong. You are trying to update a bunch of fields to new values where those fields equal the new values so of course it will not work. Also you have mixed text and parameterized sql. Don't do that. Stick to using parameters.

Also you need to rebind your grind after making updates, not just refresh.