0

ca any one correct my insert query in database

Dim hotel_book As String = "insert into hotelbooking (Userid, hotel_requirement_Types, singleroom, single_no_room,doubleroom,double_no_room) " & _"VALUES (" & userid & ", '" & ckchecked.Text & "' , & singlecheck & , & no_single_room & , & doublecheck & , &no_double_room & " )

singleroom and doubleroom are of type binary( 50)

userid , single_no_room and double_no_room are of type int

and type is nvarchar(50) of Userid, hotel_requirement_Types

please reply me

Edited by __avd: Added [code] tags.

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by __avd
0

try:

Dim hotel_book As String = "insert into hotelbooking (Userid, hotel_requirement_Types, singleroom, single_no_room,doubleroom,double_no_room) " & _"VALUES (" & userid & ", '" & ckchecked.Text & "' ," & singlecheck & "," & no_single_room & "," & doublecheck & "," &no_double_room & " )"

Edited by Eric Cute: n/a

0

i have corrected some of stuff myself but i m facing new kind of problem
that i how to convert null to zero

Dim hotel_book As String = "insert into hotelbooking (Userid, hotel_requirement_Types, singleroom, single_no_room,doubleroom,double_no_room,checkin_date,checkout_date) " & _
                      "VALUES (" & userid & ", '" & ckchecked.Text & "' , " & Convert.ToByte(boolsing) & " ," & Int32.Parse(no_single_room.Text) & "," & Convert.ToByte(booldoub) & "," & Int32.Parse(no_double_room.Text) & " ,'" & txt_checkin.Text & "' ,'" & Me.txt_checkout.Text & "' )"

want that if no_single_room.Text is null and have no value it should convert it into zero other wise Int32.Parse(no_single_room.Text) in same insert statement

Thanks

0

Hi,

You can try like this way in the query;

no_single_room.Text.Trim() == "" ? 0 : Convert.ToInt32(no_single_room.Text)

Good luck.

0

its giving me an error
Error 4 Expression expected. C:\Users\Iram\Documents\Visual Studio 2008\Projects\gfln1\gfln1\Regsiteration.aspx.vb 900 156 gfln1

Error 3 End of statement expected. C:\Users\Iram\Documents\Visual Studio 2008\Projects\gfln1\gfln1\Regsiteration.aspx.vb 900 204 gfln1

Dim hotel_book As String = "insert into hotelbooking (Userid, hotel_requirement_Types, singleroom, single_no_room,doubleroom,double_no_room,checkin_date,checkout_date) " & _
                       "VALUES (" & userid & ", '" & ckchecked.Text & "' , " & Convert.ToBoolean(singlecheck.Checked) & " ," & no_single_room.Text.Trim() == "" ? 0 : Convert.ToInt32(no_single_room.Text) & "," & Convert.ToInt32(doublecheck.Checked) & "," & Int32.Parse(no_double_room.Text) & " ,'" & txt_checkin.Text & "' ,'" & Me.txt_checkout.Text & "' )"
0

@erum

Keep practice on parameterized queries.

....
Dim hotel_book As String = "insert into hotelbooking (Userid, hotel_requirement_Types, singleroom, single_no_room,doubleroom,double_no_room,checkin_date,checkout_date) values (@Userid, @hotel_requirement_Types, @singleroom, @single_no_room,@doubleroom,@double_no_room,@checkin_date,@checkout_date)"

cmd.CommandText=hotel_book
cmd.Parameters.AddWithValue("@Userid",userid)
......
This topic has been dead for over six months. 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.