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

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 & " )"

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

Hi,

You can try like this way in the query;

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

Good luck.

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 & "' )"

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