Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi No errors in code its runs and Done
but its not update my data in data base

VB
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)
Posted
Updated 1-Jan-16 1:45am
v2
Comments
Richard MacCutchan 1-Jan-16 7:30am    
Could be any of a million reasons, and without a description of what you mean by "not working" it is hard to say which.
synctor 1-Jan-16 7:33am    
sorry about poor english and questions
this code have not any error its done but my change in "natije" field is not working in data base

1 solution

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.
 
Share this answer
 
Comments
synctor 1-Jan-16 7:37am    
i just want update "natije" field
that field is not in "after WHERE" statement
synctor 1-Jan-16 7:43am    
so whats a solution ? please Help to do that
AnvilRanger 1-Jan-16 8:59am    
You just need something like

update kharabi
set natije = @natije
where id = @id

The id should be the primary key for your table.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900