|
-
Jan 23rd, 2011, 11:47 PM
#1
Thread Starter
Junior Member
not inserting, or reading sql rows in order
i have a button and 2 text boxes to insert data
i have a button and 2 text boxes to read the data
it seems that when i insert a row, it is not being inserted as the very next row. or at least it is not reading it in order
1st. I add rows with the values (2 columns in table) 1 and 1, then 2 and 2, then 3 and 3
2nd. I read the rows, the do not come up in order 1 and 1, then 2 and 2, then 3 and 3. I will get somethign like 1 and 1, then 3 and 3, then 2 and 2,
it does read it the same way each time i read it.
to insert row i...
vb.net Code:
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
'code below inserts row
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As New SqlDataAdapter
Dim sql As String
connetionString = "Data Source=.\SQLEXPRESS;Initial Catalog=MemberList;Integrated Security=True"
connection = New SqlConnection(connetionString)
Try
connection.Open()
sql = "insert into MemberList (MemberName, MemberAge) values('" & txtInsertName.Text & "', '" & txtInsertAge.Text & "')"
adapter.InsertCommand = New SqlCommand(sql, connection)
adapter.InsertCommand.ExecuteNonQuery()
MsgBox("Row inserted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
to read the rows (text boxes change before each msgbox) i...
vb.net Code:
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
'code below reads rows and displays data
Dim sqlConn As New SqlConnection("server=.\SQLEXPRESS;Integrated Security=true; Database=memberlist;")
sqlConn.Open()
Dim sqlComm As New SqlCommand("SELECT * FROM memberlist", sqlConn)
Dim dr As SqlDataReader = sqlComm.ExecuteReader()
While dr.Read
txtReadName.Text = (dr("MemberName"))
txtReadAge.Text = (dr("MemberAge"))
MsgBox("Next")
End While
sqlConn.Close()
End Sub
Last edited by Hack; Jan 24th, 2011 at 05:59 AM.
Reason: Added Highlight Tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|