SQL Statments

  • Thread starter Thread starter Wes McCaslin
  • Start date Start date
W

Wes McCaslin

I have this application which I'm connected to a access database.I was
wondering how could i get the information form a textbox on a form to the
fields in the database. So far this is what i have tried.

Private Sub AddCommandButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddCommandButton.Click
Me.OleDbConnection1.Open()

Me.OleDbDataAdapter1.InsertCommand.CommandText = "insert into passwords
(username,password,levels)values(aaa,bbb,3)"

Me.OleDbDataAdapter1.InsertCommand.ExecuteNonQuery()

end sub
 
* "Wes McCaslin said:
I have this application which I'm connected to a access database.I was
wondering how could i get the information form a textbox on a form to the
fields in the database. So far this is what i have tried.

Private Sub AddCommandButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddCommandButton.Click
Me.OleDbConnection1.Open()

Me.OleDbDataAdapter1.InsertCommand.CommandText = "insert into passwords
(username,password,levels)values(aaa,bbb,3)"

Me.OleDbDataAdapter1.InsertCommand.ExecuteNonQuery()

ADO.NET group:

<
Web interface:

<http://msdn.microsoft.com/newsgroup...roup=microsoft.public.dotnet.framework.adonet>
 
the only problem I see with your code is the missing single quotes around
the aaa and bbb values in the insert statement.

It would however be better practice to use parameters and a command object
instead.

The new version of you code might look like this

Private Sub AddCommandButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AddCommandButton.Click
Me.OleDbConnection1.Open()
Dim cmd as new OleDBCommand("insert into passwords
(username,password,levels)values(?,?,?)",OleDBConnection1)
cmd.parameters.add("UserName","aaa")
cmd.parameters.add("password","bbb")
cmd.parameters.add("levels",3)
cmd.executenonquery ()

End Sub


Kirk
 
Back
Top