need a help (insert data) vb.net 2003

yud

New member
Joined
Feb 15, 2007
Messages
3
Programming Experience
Beginner
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;
Code Month Values
cen200501 January 1
cen200502 February 2
cen200503 March 3
cen200504 April 4
cen200505 May 5
Experiment 1, when I checked it, it’s like this; and then I deleted the information
Code Month Values
cen200505 May 5
cen200501 January 1
cen200502 February 2
cen200503 March 3
cen200504 April 4
Experiment 2, 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
Experiment 3, when I checked it, it’s like this;
Code Month Values
cen200505 May 5
cen200503 March 3
cen200502 February 2
cen200501 January 1
cen200504 April 4
the program saved random, I think there have a mistake in my coding
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
thanks for the attention :)
 
Last edited by a moderator:
vb 2003 is .net 1.1
your profile says 1.0
please correct this

take a read of the DW1 link in my signature
 
Back
Top