|
-
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
-
Jan 23rd, 2011, 11:48 PM
#2
Thread Starter
Junior Member
Re: not inserting, or reading sql rows in order
I do realize that I am connecting to the database 2 different ways, when its working ill examine how each works and figure out the best method and clean it up a bit.
thanks very much for your time and help.
-
Jan 23rd, 2011, 11:56 PM
#3
Re: not inserting, or reading sql rows in order
A table in a relational database is just a set of records, it doesn't have a concept of the "order" the rows were added. If you want a specific ordering, specify an ORDER BY in your SQL SELECT. Otherwise the DB is free to return the rows in whatever order it feels like (as in, the quickest way it can figure to access the table).
-
Jan 24th, 2011, 12:15 AM
#4
Thread Starter
Junior Member
Re: not inserting, or reading sql rows in order
well then, i thank you for your time. i have learned something.
maybe you can tell me what the proper way of connecting to the database and sending - retrieving data is.
thanks
-
Jan 24th, 2011, 12:27 AM
#5
Re: not inserting, or reading sql rows in order
Have a look in the Database Development FAQ.
Edit:
Could you please remember to wrap your code in [highlight="VB"][/highlight] tags. Thank you!
Last edited by Nightwalker83; Jan 24th, 2011 at 12:31 AM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jan 24th, 2011, 06:02 AM
#6
Re: not inserting, or reading sql rows in order
Moved To Database Development
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
|