0

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,,,,,,,

Edited by kanuri1: not clear

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by reach_yousuf
0

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

0

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.............

0

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...

Edited by reach_yousuf: n/a

0

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!!!

Edited by reach_yousuf: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.