I need a help
I have a form like this in vb.net 2003, when I put value in textbox1 until textbox5 and then I click button save. The program will save the information into quest table.
QUEST
January textbox1 textbox13(year at the time)
February textbox2
March textbox3
April textbox4
May textbox5
Button_save
Button_back
My problem is
After that I saved it and then I checked into quest table and I found it wasn’t like I hoped.
What I hope is;
What should I do for the coding? My coding was:
thanks for the attention
I have a form like this in vb.net 2003, when I put value in textbox1 until textbox5 and then I click button save. The program will save the information into quest table.
QUEST
January textbox1 textbox13(year at the time)
February textbox2
March textbox3
April textbox4
May textbox5
Button_save
Button_back
My problem is
After that I saved it and then I checked into quest table and I found it wasn’t like I hoped.
What I hope is;
Experiment 1, when I checked it, it’s like this; and then I deleted the informationCode Month Values
cen200501 January 1
cen200502 February 2
cen200503 March 3
cen200504 April 4
cen200505 May 5
Experiment 2, when I checked it, it’s like this;Code Month Values
cen200505 May 5
cen200501 January 1
cen200502 February 2
cen200503 March 3
cen200504 April 4
Experiment 3, when I checked it, it’s like this;Code Month Values
cen200505 May 5
cen200504 April 4
cen200503 March 3
cen200502 February 2
cen200501 January 1
the program saved random, I think there have a mistake in my codingCode Month Values
cen200505 May 5
cen200503 March 3
cen200502 February 2
cen200501 January 1
cen200504 April 4
What should I do for the coding? My coding was:
VB.NET:
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
Dim insertQuery As String
Dim hasil As String
Dim cmd As MySqlCommand
Dim i As Integer
For i = 1 To 5
If i = 1 Then
insertQuery = "insert into quest values('cen" & TextBox13.Text & "01','January','" & textbox1.Text & "')"
cmd = New MySqlCommand(insertQuery, Conn)
hasil = cmd.ExecuteNonQuery()
ElseIf i = 2 Then
insertQuery = "insert into quest values('cen" & TextBox13.Text & "02','February','" & TextBox2.Text & "')"
cmd = New MySqlCommand(insertQuery, Conn)
hasil = cmd.ExecuteNonQuery()
ElseIf i = 3 Then
insertQuery = "insert into quest values('cen" & TextBox13.Text & "03','March','" & TextBox3.Text & "')"
cmd = New MySqlCommand(insertQuery, Conn)
hasil = cmd.ExecuteNonQuery()
ElseIf i = 4 Then
insertQuery = "insert into quest values('cen" & TextBox13.Text & "04','April','" & TextBox4.Text & "')"
cmd = New MySqlCommand(insertQuery, Conn)
hasil = cmd.ExecuteNonQuery()
ElseIf i = 5 Then
insertQuery = "insert into quest values('cen" & TextBox13.Text & "05','May','" & TextBox5.Text & "')"
cmd = New MySqlCommand(insertQuery, Conn)
hasil = cmd.ExecuteNonQuery()
End If
Next i
Try
If (hasil > 0) Then
MessageBox.Show("Insert Record Sucess")
clear()
End If
Catch ex As MySqlException
MessageBox.Show("Insert record failed : " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
cmd.Connection.Close()
cmd.Dispose()
End Sub
Last edited by a moderator: