473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

store date value into database (vb.net)

15
Hi,

I have problem with my simple program. Actually, I try to store date value in form of date format (mm/dd/yyyy). I got message that inform me "number of query values and destination fields are not the same". I provide example coding below to help you all understand. Please help me, it urgent....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oConn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" & "C:\Documents and Settings\Crazy_Frog\My Documents\Visual Studio Projects\SportPlanet1\Data\spData.mdb")
Dim oApt As New OleDbDataAdapter("SELECT [tbl_name] FROM [database_name]", oConn)
Dim sql As String = String.Empty
Try
If _id = 0 Then
sql = "INSERT INTO [database_name] Values('" & TextBox4.Text & "')"
End If
oConn.Open()
Dim oComm As New OleDbCommand(sql, oConn)
oComm.ExecuteNonQuery()
oConn.Close()
MsgBox("Data Save.")
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
Feb 27 '08 #1
2 2549
Hello
The SQL Insert Statement Syntax is like this
Statement I
INSERT INTO TABLENAME(COLNAME) VALUES(COL_VALUE)
Statement II
INSERT INTO TABLENAME VALUES(COL_VALUE)
The above query works without column name if you are specifying all the column values in the VALUES.

Seems in this case
sql = "INSERT INTO [database_name] Values('" & TextBox4.Text & "')"

the table database_name has more than one column.
So use
sql = "INSERT INTO database_name(Column_name) Values('" & TextBox4.Text & "')"

Hope this helps you.
Happy Programming!
Hi,

I have problem with my simple program. Actually, I try to store date value in form of date format (mm/dd/yyyy). I got message that inform me "number of query values and destination fields are not the same". I provide example coding below to help you all understand. Please help me, it urgent....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oConn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" & "C:\Documents and Settings\Crazy_Frog\My Documents\Visual Studio Projects\SportPlanet1\Data\spData.mdb")
Dim oApt As New OleDbDataAdapter("SELECT [tbl_name] FROM [database_name]", oConn)
Dim sql As String = String.Empty
Try
If _id = 0 Then
sql = "INSERT INTO [database_name] Values('" & TextBox4.Text & "')"
End If
oConn.Open()
Dim oComm As New OleDbCommand(sql, oConn)
oComm.ExecuteNonQuery()
oConn.Close()
MsgBox("Data Save.")
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
Feb 27 '08 #2
Plater
7,872 Expert 4TB
There are a number of good examples on how to use INSERT.
This one is pretty good at explaining how to insert data into different columns:
http://www.w3schools.com/sql/sql_insert.asp
Feb 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Flipmode | last post by:
I am fairly novice at VB and access in particular and I am having problems trying store a date into database field. This is the scenario I am faced with. I want to when click on a pause button...
2
by: Des | last post by:
I have tried various configurations of putting todays date into an sql Server 2000 database The field is set to Datetime Length(8) it displays 01/01/1900 after insertion What I have is Dim...
10
by: melissa.nava | last post by:
Here is my code: ***** Public Property DOB() As Date Get Try DOB = (msBirthMonth + "/" + msBirthDay + "/" + msBirthYear)
6
by: Aussie Rules | last post by:
Hi, I have a datepicker that show a calender. The user picks a date and the time component is always 00:00. I then have a drop down that provides a list of times, (10:00, 11:00 etc), and I...
2
by: MackTheKnife | last post by:
Hi, I'm trying to write a java.sql.Date to a database and the minutes/ seconds etc. are not being written. I've seen and tested many examples found via searches and still have come up with...
3
by: ruchikagupta | last post by:
i have 3 dropwown lists for day month and year and i want to store date in one field in database using c#.net in sql server. how to combine the values n form a date
8
by: Rob Wilkerson | last post by:
Surprisingly (at least to me), there doesn't seem to be a built-in function to validate a date value (like, say, is_date()). Given that, is there a best practice for determining whether a value is...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
4
by: ghjk | last post by:
I want to compare user entered date with data base datetime value. Database value in datetime type and first i want to extract date part and then compare with user entered value. This is my query....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.