Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,542 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,817 people online right now. Registration is fast and FREE... Join Now!




sql insert statement problem for date

 
Reply to this topicStart new topic

sql insert statement problem for date

saikoTkT
21 Aug, 2008 - 11:17 PM
Post #1

New D.I.C Head
*

Joined: 21 Aug, 2008
Posts: 2

I have 3 combo boxes for date,that is day, month and year
i'm confusing with my insert statement

CODE
Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
        Dim cn As SqlConnection
        Dim cm As SqlCommand
        Dim int As Integer 'integer holds the number of records inserted
        Dim a As String
        Dim b As String

        'provide password for sql server
        cn = New SqlConnection("server=localhost;uid=sa;pwd=123;database=Enrollment")
        cn.Open()
        'insert student's details
        cm = New SqlCommand("INSERT INTO StudentDetails VALUES ('" & Me.StudentNameTxt.Text & "','" & DayCb.SelectedText & "+ " / " +  " & MonthCb.SelectedText & " + " / " +" & YearCb.SelectedText & "' ,'" & Me.BirthcertTxt.Text & "','" & MaleChk.Checked & "+ " / " + " & FemaleChk.Checked & "','" & Me.ContactNumTxt.Text & "','" & Me.CitizenTxt.Text & "','" & Me.CityTxt.Text & "','" & Me.StateTxt.Text & "','" & Me.PostCodeTxt.Text & "','" & Me.AddressRichTxt.Text & "')", cn)
        If MaleChk.Checked Then
            a = "Male"
        ElseIf FemaleChk.Checked Then
            b = "Female"

        End If

        int = cm.ExecuteNonQuery()
        'if details save successful
        MessageBox.Show("Succeed Save Details!" & int)
        cn.Close()

    End Sub

    


it debug successful but when i press save button it appears error as below:
conversion from string "+" to type 'Double' is not valid

Besides that, i put a column for date in my sql database table
Is it correct?
User is offlineProfile CardPM
+Quote Post

thava
RE: Sql Insert Statement Problem For Date
22 Aug, 2008 - 01:05 AM
Post #2

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 450



Thanked: 18 times
Dream Kudos: 50
My Contributions
try this
CODE

cm = New SqlCommand("INSERT INTO StudentDetails VALUES ('" & Me.StudentNameTxt.Text & "','" &  MonthCb.SelectedText & "/"  & DayCb.SelectedText & "/"  & YearCb.SelectedText & "' ,'" & Me.BirthcertTxt.Text & "','" & MaleChk.Checked & "+ " / " + " & FemaleChk.Checked & "','" & Me.ContactNumTxt.Text & "','" & Me.CitizenTxt.Text & "','" & Me.CityTxt.Text & "','" & Me.StateTxt.Text & "','" & Me.PostCodeTxt.Text & "','" & Me.AddressRichTxt.Text & "')", cn)

check will it works

This post has been edited by thava: 22 Aug, 2008 - 01:07 AM
User is offlineProfile CardPM
+Quote Post

saikoTkT
RE: Sql Insert Statement Problem For Date
22 Aug, 2008 - 03:04 AM
Post #3

New D.I.C Head
*

Joined: 21 Aug, 2008
Posts: 2

QUOTE(thava @ 22 Aug, 2008 - 02:05 AM) *

try this
CODE

cm = New SqlCommand("INSERT INTO StudentDetails VALUES ('" & Me.StudentNameTxt.Text & "','" &  MonthCb.SelectedText & "/"  & DayCb.SelectedText & "/"  & YearCb.SelectedText & "' ,'" & Me.BirthcertTxt.Text & "','" & MaleChk.Checked & "+ " / " + " & FemaleChk.Checked & "','" & Me.ContactNumTxt.Text & "','" & Me.CitizenTxt.Text & "','" & Me.CityTxt.Text & "','" & Me.StateTxt.Text & "','" & Me.PostCodeTxt.Text & "','" & Me.AddressRichTxt.Text & "')", cn)

check will it works


i've try it
still the same error:conversion from string "+" to type 'Double' is not valid
However,thank youfor your help
User is offlineProfile CardPM
+Quote Post

WayneSpangler
RE: Sql Insert Statement Problem For Date
22 Aug, 2008 - 05:09 AM
Post #4

D.I.C Head
**

Joined: 22 Mar, 2008
Posts: 102



Thanked: 8 times
My Contributions
It is terible trying to read something that is all on one line. Learn to break it down either as:
str="text"
str &= "more text"
etc.
or:
str="text" _
"more text" _
etc.
Here is your code in the second form. By looking at it I'm sure you will see the problem. However I marked the area.
CODE
        Dim cm = New SqlCommand("INSERT INTO StudentDetails VALUES ('" & _
                                Me.StudentNameTxt.Text & _
                                "','" & _
                                MonthCb.SelectedText & _
                                "/" & _
                                DayCb.SelectedText & _
                                "/" & _
                                YearCb.SelectedText & _
                                "' ,'" & _
                                Me.BirthcertTxt.Text & _
                                "','" & _
                                MaleChk.Checked & _
                                "+ " / " + "  & _               <<<<<<<The problem is here
                                FemaleChk.Checked & _
                                "','" & _
                                Me.ContactNumTxt.Text & _
                                "','" & _
                                Me.CitizenTxt.Text & _
                                "','" & _
                                Me.CityTxt.Text & _
                                "','" & _
                                Me.StateTxt.Text & _
                                "','" & _
                                Me.PostCodeTxt.Text & _
                                "','" & _
                                Me.AddressRichTxt.Text & _
                                "')", cn)


This post has been edited by WayneSpangler: 22 Aug, 2008 - 05:10 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sql Insert Statement Problem For Date
22 Aug, 2008 - 06:22 PM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,947



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
The problem actually occurs in three places, replace the / with a ,.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 10:39PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month