为什么我的代码不起作用? [英] why my code is not working ?

查看:114
本文介绍了为什么我的代码不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


代码没有错误运行和完成

但它没有更新数据库中的数据



< pre lang =vb> con.ConnectionString = con_str
con.Open()
com.Connection = con
com.CommandText = 更新kharabi SET natije = @ natije where(kharabi_sal ='& TextBox10.Text& '和kharabi_mah ='& TextBox6.Text& '和kharabi_rooz ='& TextBox5.Text& '和shomare = '& TextBox1.Text& 'and bookht ='& TextBox2.Text& 'and method ='& ComboBox1.Text& '和moshkel ='& TextBox3.Text& 'and source ='& ComboBox2.Text& '和markaz ='& ComboBox3.Text& ')

com.Parameters.AddWithValue( natije,TextBox4.Text)

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

解决方案

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



接下来您的更新声明可能是错误的。您正在尝试将一堆字段更新为新值,其中这些字段等于新值,因此它当然不起作用。你也有混合文本和参数化的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.


这篇关于为什么我的代码不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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