|
-
how to insert date to OleDb DataBase(VB.Net windows Application)
i am trying to insert a date to OleDb data base. its Field Type is DateTime.
what is wrong with my insert query? by avoiding the date field using this query
ssql = "INSERT INTO mytable (Address,Name) VALUES (@address,@name)"
i can insert Address and name to database.
something is wrong in the syntax for Date Field. pls help me.This is my code.it shows Syntax error in INSERT INTO Statement
Dim insertOk As Boolean = True
Dim sqlcon As OleDbConnection = New OleDbConnection("Data Source=C:\Debug\Data.mdb; Provider=Microsoft.Jet.OLEDB.4.0; User ID=Admin")
Try
sqlcon.Open()
ssql = "INSERT INTO mytable (Address,Name,Date) VALUES (@address,@name,@dt)"
sqlcmd = New OleDbCommand(ssql, sqlcon)
sqlcmd.Parameters.Add("@address", TextBox2.Text)
sqlcmd.Parameters.Add("@name", TextBox1.Text)
sqlcmd.Parameters.Add("@dt", Convert.ToDateTime(DateTimePicker1.Value.ToString) )
sqlcmd.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox(ex.Message.ToString)
insertOk = False
Finally
sqlcon.Close()
End Try
If insertOk Then
MsgBox("Details Submitted Successfully!")
Else : MsgBox("There was an error saving your data!")
End If
Similar Threads
-
By sandhya.o.k in forum .NET
Replies: 1
Last Post: 12-06-2006, 12:32 PM
-
By Urbaud in forum VB Classic
Replies: 4
Last Post: 07-30-2006, 10:50 PM
-
By lew26 in forum Database
Replies: 1
Last Post: 01-26-2006, 10:54 PM
-
By Go_Diamond in forum VB Classic
Replies: 12
Last Post: 03-30-2005, 01:59 AM
-
By Shailaza in forum ASP.NET
Replies: 0
Last Post: 06-15-2000, 07:08 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks