By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Code to insert record

P: n/a
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(newCustomersR ow)
My Code so far:Dim newContactsRow As ContactFormData.tblContactForm1RowDim
ContactFormData1 As ContactFormDatanewContactsRow =
ContactFormData1.tblContactForm1.NewtblContactForm 1Row()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
Mar 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Mar 22 '06 #2

P: n/a
I'll post to code for anyone interested a little later.
Mar 22 '06 #3

P: n/a
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
Mar 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.