Hello Stephany,
Console.WriteLine(strSQL) ???
Here is my problem. How would I have ever known that method without
coming on the newsgroup. Where do you learn this stuff? There never seem
to be strictly working examples of methods anywhere. I mean complete
examples of common methodology. It always seems I have to spend hours
sreaching and searching for examples and hoping I can get them to work.
Before I explore your suggested method, here is what I have done, and it
is close. I parametized the SQL Statement. If it is acceptable practice,
I would like to get it working before trying something different.
Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" + Server.MapPath("_database/DragonImporting.mdb")
Dim myConn As New Data.OleDb.OleDbConnection(connectString)
myConn.Open()
Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDealer,
txtOtherCustType, chkStandardBags, chkCustomBags,txtOtherBags) VALUES
(@txtName, @txtCompany, @txtPhone, @txtEmail.Text, @txtComment,
@chkGrower, @chkProduceDealer, @txtOtherCustType,
@chkStandardBags.Checked, @chkCustomBags, @txtOtherBags)"
Dim myCmd As New Data.OleDb.OleDbCommand(strSQL, myConn)
myCmd.Parameters.Add("txtName", Data.OleDb.OleDbType.VarChar).Value =
txtName.Text
myCmd.Parameters.Add("txtCompany", Data.OleDb.OleDbType.VarChar).Value =
txtCompany.Text
myCmd.Parameters.Add("txtPhone", Data.OleDb.OleDbType.VarChar).Value =
txtPhone.Text
myCmd.Parameters.Add("txtEmail", Data.OleDb.OleDbType.VarChar).Value =
txtEmail.Text
myCmd.Parameters.Add("txtComment", Data.OleDb.OleDbType.VarChar).Value =
txtComment.Text
myCmd.Parameters.Add("chkGrower", Data.OleDb.OleDbType.Boolean).Value =
chkGrower.Text
myCmd.Parameters.Add("chkProduceDealer",
Data.OleDb.OleDbType.Boolean).Value = chkProduceDealer.Text
myCmd.Parameters.Add("txtOtherCustType",
Data.OleDb.OleDbType.VarChar).Value = txtOtherCustType.Text
myCmd.Parameters.Add("chkStandardBags",
Data.OleDb.OleDbType.Boolean).Value = chkStandardBags.Text
myCmd.Parameters.Add("chkCustomBags", Data.OleDb.OleDbType.Boolean).Value
= chkCustomBags.Text
myCmd.Parameters.Add("txtOtherBags", Data.OleDb.OleDbType.VarChar).Value =
txtOtherBags.Text
myCmd.ExecuteNonQuery()
myConn.Close()
I get an error:
Line 125: myCmd.ExecuteNonQuery()
[FormatException: String was not recognized as a valid Boolean.]
I set Strict to True on the document, but couldn't find the same property
sheet for the project. The error result was the same.
The chk box controls are feeding Yes/No fields in and Access DB. Also the
txtComment field in Access is a memo field. I don't know if varchar is
approriate for that.
Is my methodogy ok for this or should I change it?
Thank you for the help. It is greatly appreciated.
Mark
Stephany Young said:
It's not a matter of not wanting the code to compile. If you set the
Option Strict property of your project to ON, you will find that the
compiler will 'spit it's dummy' at all the places in your code where
there are problems.
Concatenate is the term for joing strings together and & is the
concatenation operator. E.g. You can read "AAA" & "BBB" as "AAA"
concatenate "BBB" - the result of the concatenation is "AAABBB".
Try this code, it works as expected. Make sure you copy and paste it
exactly as it is.
Dim txtName As New TextBox
txtName.Text = "A"
Dim txtCompany As New TextBox
txtCompany.Text = "B"
Dim txtPhone As New TextBox
txtPhone.Text = "C"
Dim txtEmail As New TextBox
txtEmail.Text = "D"
Dim txtComment As New TextBox
txtComment.Text = "E"
Dim chkGrower As New CheckBox
chkGrower.Checked = False
Dim chkProduceDealer As New CheckBox
chkProduceDealer.Checked = True
Dim txtOtherCustType As New TextBox
txtOtherCustType.Text = "F"
Dim chkStandardBags As New CheckBox
chkStandardBags.Checked = False
Dim chkCustomBags As New CheckBox
chkCustomBags.Checked = True
Dim txtOtherBags As New TextBox
txtOtherBags.Text = "G"
Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, " & _
"txtCompany, txtPhone, txtEmail, txtComment, chkGrower, chkProduceDealer,
" & _
" txtOtherCustType, chkStandardBags, chkCustomBags,txtOtherBags)" & _
" VALUES ('" & txtName.Text & "','" & txtCompany.Text & "','" & _
txtPhone.Text & "','" & txtEmail.Text & "','" & txtComment.Text & _
"','" & chkGrower.Checked & "','" & chkProduceDealer.Checked & _
"','" & txtOtherCustType.Text & "','" & chkStandardBags.Checked & _
"','" & chkCustomBags.Checked & "','" & txtOtherBags.Text & "');"
Console.WriteLine(strSQL)