Last post Sep 03, 2011 05:34 AM by anant718
Sep 01, 2006 05:12 PM|aspnet_novice|LINK
I am about to go crazy over trying to insert a row of data in a new MS ACCESS database. The database has 4 columns, "Email", "Name", "CompanyName", & "Date". The Date field is set as DATE/TIME-General Date in MS ACCESS, and all other fields are TEXT.
Here is my code below. Hopefully, someone can help me find the error in my code.
Dim conCoaxis As OleDbConnection
Dim strInsert As String
Dim cmdInsert As OleDbCommand
Dim dtmDate As DateTime
dtmDate = DateTime.Now()
conCoaxis = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\WWWRoot\DOMAINNAME\database\email.mdb")
strInsert = "INSERT INTO List (Email, Name, CompanyName, Date) Values (@Email, @Name, @CompanyName, @Date)"
cmdInsert = New OleDbCommand( strInsert, conCoaxis )
cmdInsert.Parameters.Add( "@Email", txtEmail.Text )
cmdInsert.Parameters.Add( "@Name", txtName.Text )
cmdInsert.Parameters.Add( "@CompanyName", txtCompany.Text )
cmdInsert.Parameters.Add( "@Date", OleDbType.Date).Value = dtmDate.ToString("g")
Response.Write("Updated Successfully!<p> </p><p> </p><p> </p>")
Sep 02, 2006 08:18 PM|deokule2003|LINK
"Date" is a reserved word in MS Access. To know more reserved words in Access refer following link:
So, either use other column name in place of "date". Or modify your insert statement as given below:
strInsert = "INSERT INTO List (Email, Name, CompanyName, [Date]) Values (@Email, @Name, @CompanyName, @Date)"
Square brakets around "Date"
Sep 03, 2006 08:44 PM|aspnet_novice|LINK
Thanks for the reply. I got it all figured out. You we're right about the reserved words. NAME is also a reserved word. However, I DIDN'T know that you could enclose the column name in brackets ( [NAME], [DATE] ) to make it work. That is very helpful
Thanks for your help,
Sep 05, 2006 01:59 AM|mpMS|LINK
Need help on this using .NET 2.0 . I think the code applies to .NET 1.x . I have this code that I cannot figure out the cause of the problem:
I want to insert values from textbox-based input and upon
clicking the Create button, these command lines will run. It didn't work! It
points to the "test.Insert()" line that indicates that "Keyword not
supported: 'provider'". See the code behind below:
Protected Sub btnCreate_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
Dim test As SqlDataSource = New SqlDataSource()
test.InsertCommand = "INSERT INTO [tblaccounts] ([UserName],
[FName], [LName], [Email], [Department],[Password]) VALUES (@UserName,
@FName, @LName, @Email, @Dept, @Password)"
test.Insert() <<<<<<<<------ This line has an error
Label7.Visible = True
Hope you might help...
Sep 07, 2006 10:36 AM|Iori_Jay|LINK
[quote user="mpMS"] It points to the "test.Insert()" line that indicates that "Keyword not supported: 'provider'"
I guess that's because SqlDataSource.ConnectionString doesn't accept the Provider keyword, instead, you need to set the SqlDataSource.ProviderName to System.Data.OleDb. For more information, you can take a look at this link:
Sep 03, 2011 05:34 AM|anant718|LINK
Can you please give the above code in C#?