Well, it could be that you are using the same INSERT query for your OleDbCommand.ExecuteNonQuery
and for your OldDataAdapter.Fill - I'm pretty sure that if you replace data adapter command with a SELECT query, things will work rather better... :laugh:
BTW: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead - it's a lot, lot safer!
"will you explain how to use parametrized queries plzzz...."
I will ignore the "replay fast" instruction - this one time, and one time only. Any future usages will get you no further response from me. It is rude, arrogant and unnecessary, and all it will do is annoy people. Please consider the possible effects of what you are about to say
before you send or post a message!
Using con As New SqlConnection(strConnect)
con.Open()
Using com As New SqlCommand("INSERT INTO EXA (myColumn1, myColumn2) VALUES (@C1, @C2)", con)
com.Parameters.AddWithValue("@C1", TextBox1.Text)
com.Parameters.AddWithValue("@C2", TextBox2.Text)
com.ExecuteNonQuery()
End Using
End Using
In addition, you should always list the columns you want to insert data into (I called them myColumn1 and myColumn2) - it helps prevent mistakes if the database is changed at a later date, and makes the code more readable. You can use any name for the parameters - I used C1 and C2 because I have no idea what the text boxes contain! (See what I mean about readability?)
And please, stop using Visual Studio default names for controls! Calling them "tbUserName" and "tbAddress" or whatever instead of "Textbox1" and "TextBox2" makes your code more readable, and it can be quicker to type because Intellisense can figure it out for you...