[thelist] using a form.text object in an Insert command

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Mon Dec 20 21:50:43 CST 2004


Hi Casey,

	First of all, you might want to seriously consider joining an
ASP.NET list like the one at http://tinyurl.com/45bhs (not that this
group isn't helpful, but you may find you get more focused attention in
other forums).  Second, I strongly suggest putting your SQL into its own
string variable like this:

Dim sSQL As String

sSQL = "INSERT INTO Members(fname) VALUES('" & fname.Text & "')"

	This way you have a more readable, maintainable piece of code,
and if your query errors out, you can easily get the value of this
string and test it directly against your database.

Cheers,

Peter

-----Original Message-----
From: thelist-bounces at lists.evolt.org On Behalf Of Casey Crookston

myAddMemberCmd = New OleDbCommand("INSERT INTO members (fname) VALUES
('Fubar')", myDbConn)

This works fine.  But what if the value of fname is held in fname.text
after a form submission?  Confused on the syntax.

Here's all the code:

 Sub Submit_Button_Click(Sender As Object, E As EventArgs)

   Dim myDbConn As OleDbConnection
   Dim myAddMemberCmd As OleDbCommand

   myDbConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data
Source=C....mdb")
   myAddMemberCmd = New OleDbCommand("INSERT INTO members (fname) VALUES
('fname.text')", myDbConn)
   myDbConn.open()
   myAddMemberCmd.ExecuteNonQuery()
   myDbConn.close()

 End Sub




More information about the thelist mailing list