Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate SQL statement in vb.net
    text
    copied!<p>I am new in VB.NET and as well as SQL. I want to update records in my database. I made a dummy in my database. </p> <p>Example the values are: ID = 1, name=Cath, age=21 </p> <p>In my interface made in VB.NET, I update the values example : name = txtName.Text and age = txtAge.Text where ID = 1. This is in my main form. In my main form, I have "view" button informing that by clicking that button, new form would pop up and would view the updated values by the user. The program does not have any errors except that when I want to update again the values in my SQL, It record BUT when I click "view" button again, It will show the previous inputted by the user (the first update upon running the interface). What should be the solution?</p> <p>This is my code:</p> <p>Mainform:</p> <pre><code>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SQLConnection.ConnectionString = ServerString Try If SQLConnection.State = ConnectionState.Closed Then SQLConnection.Open() MessageBox.Show("Successful connection") Else 'SQLConnection.Close() MessageBox.Show("Connection is closed") End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Public Sub SaveNames(ByRef SQLStatement As String) Dim cmd As MySqlCommand = New MySqlCommand With cmd .CommandText = SQLStatement .CommandType = CommandType.Text .Connection = SQLConnection .ExecuteNonQuery() End With MsgBox("Successfully Added!") End Sub Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click Dim date_now As String date_now = Format(dtpDate.Value, "yyyy-MM-dd") Dim SQLStatement As String = "UPDATE people SET name='" &amp; txtName.Text &amp; "', date ='" &amp; date_now &amp; "' WHERE 1" SaveNames(SQLStatement) End Sub </code></pre> <p>Form 2: (where the updated data would be viewed)</p> <pre><code> Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SQLConnection.ConnectionString = ServerString Try If SQLConnection.State = ConnectionState.Closed Then SQLConnection.Open() '====retrieve / update values in database============= Dim SQLStatement As String = "SELECT name, date FROM people" ViewInfos(SQLStatement) Else 'SQLConnection.Close() MessageBox.Show("Connection is closed") End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Public Sub ViewInfos(ByRef SQLStatement As String) Dim cmd As MySqlCommand = New MySqlCommand With cmd .CommandText = SQLStatement .CommandType = CommandType.Text .Connection = SQLConnection .ExecuteNonQuery() End With '--read the records in database in phpmyadmin gui--- Dim myReader As MySqlDataReader = cmd.ExecuteReader If myReader.Read Then lblName.Text = myReader.GetString(0) lblDate.Text = myReader.GetString(1) End If myReader.Close() MsgBox("Records Successfully Retrieved") End Sub </code></pre> <p>Any help would be appreciated. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload