Code to insert record

M

Mark A. Sam

Hello,

I am using Visual Web Developer and the .net 2.0 framework. My intention is
to send an email then insert the form's field values into an Access Table.

I created a dataset called ContactFormData.xsd. I found code in Help, to
add date to a Typed Dateset. It seems like what I want but I can't recreate
it.

Code From Help:
Dim newCustomersRow As NorthwindDataSet.CustomersRow
newCustomersRow = NorthwindDataSet1.Customers.NewCustomersRow()

newCustomersRow.CustomerID = "ALFKI"
newCustomersRow.CompanyName = "Alfreds Futterkiste"

NorthwindDataSet1.Customers.Rows.Add(newCustomersRow)
My Code so far:Dim newContactsRow As ContactFormData.tblContactForm1RowDim
ContactFormData1 As ContactFormDatanewContactsRow =
ContactFormData1.tblContactForm1.NewtblContactForm1Row()In the Code editor
the variable ContactFormData1 in line 3 of my code, is underlined with a
ControlTip message, "Variable 'ContactFormData1' is used before it has been
assigned a value. A null reference value could result at runtime."I Dim'd
ContactFormData1 becuase it needed to be declared even though this isn't in
the help example. I'm just blindly following the help example. Any help in
how to write this procedure is appreciated.God Bless,Mark A. Sam
 
M

Mark A. Sam

I got this so far to run without error. I think I just need to know how to
execute myCmd. I don't know where it will put the data, but if it gets it
into the table, it will be progresss for me.

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 VALUES ( 'Bubba,
Jr.','Bubba's Best Coffee' );"

Dim myCmd As New Data.OleDb.OleDbCommand(strSQL, myConn)

myConn.Close()



Thanks for any help.
 
M

Mark A. Sam

If you are interested, this works from a button on a webform"

Protected Sub btnInsertOLEDB_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnInsertOLEDB.Click

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)
VALUES ('" + txtName.Text + "','" + txtCompany.Text + "');"

Dim myCmd As New Data.OleDb.OleDbCommand(strSQL, myConn)

myCmd.ExecuteNonQuery()

myConn.Close()

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top