hi,i want to insert booking_no as combination of year and sno(year/sno) into database here iam giving the code as follows,,,,,,,,,
here sno(serial number is automatically generated when page is loaded) started from 1.........

Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("guest1").ConnectionString())        
    Dim booking_no, sno As String
 If Len(sno) = 1 Then
            sno = "0000" + CStr(sno)
        End If
        If Len(sno) = 2 Then
            sno = "000" + CStr(sno)
        End If
        If Len(sno) = 3 Then
            sno = "00" + CStr(sno)
        End If
        If Len(sno) = 4 Then
            sno = "0" + CStr(sno)
        End If
        If Len(sno) = 5 Then
            sno = "" + CStr(sno)
        End If

        booking_no = CStr(year) & "/" & sno
conn.open()
Dim insert As New SqlClient.SqlCommand("insert into guesthouse(booking_no,sno) values('" & booking_no & "' ,'" & sno & "' ", conn)
        insert.ExecuteNonQuery()
conn.close()

but here booking_no was not inserted properly,it was inserted as "0/ ",,
iwant to insert booking_no as "2010/sno" ,
,,,pls help me,urgent,,,,,,,

Recommended Answers

All 4 Replies

hi,i want to insert booking_no as combination of year and sno(year/sno) into database here iam giving the code as follows,,,,,,,,,
here sno(serial number is automatically generated when page is loaded) started from 1.........

Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("guest1").ConnectionString())        
    Dim booking_no, sno As String
 If Len(sno) = 1 Then
            sno = "0000" + CStr(sno)
        End If
        If Len(sno) = 2 Then
            sno = "000" + CStr(sno)
        End If
        If Len(sno) = 3 Then
            sno = "00" + CStr(sno)
        End If
        If Len(sno) = 4 Then
            sno = "0" + CStr(sno)
        End If
        If Len(sno) = 5 Then
            sno = "" + CStr(sno)
        End If

        booking_no = CStr(year) & "/" & sno
conn.open()
Dim insert As New SqlClient.SqlCommand("insert into guesthouse(booking_no,sno) values('" & booking_no & "' ,'" & sno & "' ", conn)
        insert.ExecuteNonQuery()
conn.close()

but here booking_no was not inserted properly,it was inserted as "0/ ",,
iwant to insert booking_no as "2010/sno" ,
,,,pls help me,urgent,,,,,,,

Hi kanuri

I suspect your sno is nothing at the initial stage, try to assign default value whne it is nothing after declaration. pls. debug and see what exactly happening..

Dim booking_no, sno As String
if isnothing(sno) then sno = 1 ' or anything u want

let me know if u need further help

Regards

Hi kanuri

I suspect your sno is nothing at the initial stage, try to assign default value whne it is nothing after declaration. pls. debug and see what exactly happening..

Dim booking_no, sno As String
if isnothing(sno) then sno = 1 ' or anything u want

let me know if u need further help

Regards

sno is taken from textbox ,we gven sno manually .......
if we give sno as 9 then booking_no should be 2010/9....
.........your given code is not working properly,,,,,,,,
pls give me the correct code.............

sno is taken from textbox ,we gven sno manually .......
if we give sno as 9 then booking_no should be 2010/9....
.........your given code is not working properly,,,,,,,,
pls give me the correct code.............

where are you assigning sno = yourtextbox.text ?? paste your full page code...

hi,i want to insert booking_no as combination of year and sno(year/sno) into database here iam giving the code as follows,,,,,,,,,
here sno(serial number is automatically generated when page is loaded) started from 1.........

Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("guest1").ConnectionString())        
    Dim booking_no, sno As String
 If Len(sno) = 1 Then
            sno = "0000" + CStr(sno)
        End If
        If Len(sno) = 2 Then
            sno = "000" + CStr(sno)
        End If
        If Len(sno) = 3 Then
            sno = "00" + CStr(sno)
        End If
        If Len(sno) = 4 Then
            sno = "0" + CStr(sno)
        End If
        If Len(sno) = 5 Then
            sno = "" + CStr(sno)
        End If

        booking_no = CStr(year) & "/" & sno
conn.open()
Dim insert As New SqlClient.SqlCommand("insert into guesthouse(booking_no,sno) values('" & booking_no & "' ,'" & sno & "' ", conn)
        insert.ExecuteNonQuery()
conn.close()

but here booking_no was not inserted properly,it was inserted as "0/ ",,
iwant to insert booking_no as "2010/sno" ,
,,,pls help me,urgent,,,,,,,

This should work, add the following code

Private Function GetSno() As String

        Dim sno As String = txtProductNumber.Text

        Select Case sno.Length
            Case 1
                sno = Today.Year.ToString+ "/" + "0000" + txtProductNumber.Text
            Case 2
                sno = Today.Year.ToString+ "/" + "000" + txtProductNumber.Text
            Case 3
                sno = Today.Year.ToString+ "/" + "00" + txtProductNumber.Text
        End Select
        Return sno
    End Function

and place this function here

Dim insert As New SqlClient.SqlCommand("insert into guesthouse(booking_no,sno) values('" & GetSno() & "' ,'" & sno & "' ", conn)

Pls. mark as solved!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.