Saving information from .NET Listbox into SQL Server 2000

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Saving information from .NET Listbox into SQL Server 2000

 
0
  #11
Jan 26th, 2006
well, You are setting up the cmd, but I don't see you executing it anywhere
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Saving information from .NET Listbox into SQL Server 2000

 
0
  #12
Jan 26th, 2006
Can i also point out some problems/areas of improvement?
1. dont post your real connection string anywhere in public and especially not in forums
2. When you do implement the command execute only the first seat will be saved as you didnt loop through the others
3. Why do you iterate through all the selected items in the list, comma delimit them then go through that list pulling them out one by one again?
4. Please avoid writing sql queries in code. Use stored procedures. I dont know if you plan on using this in the real world or if it is just a project but if you have a webpage with sql code behind it from textboxes etc it takes me less than 10 seconds to get into your database and do whatever i want - read, write, delete and i could probably get into every database on the server from there. Its called SQL injection and it is #1 on hackers things to try on a website. Even if it is just a project, try and get into the habit of writing stored procs so you wont accidently leave sql code in your webpage on a live site one day.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: Saving information from .NET Listbox into SQL Server 2000

 
0
  #13
Jan 27th, 2006
Thanks, i manage to execute it, cmd.ExecuteNonQuery() . Left it out. But now i got this error. What's the problem?

Server Error in '/WebApplication5' Application.
--------------------------------------------------------------------------------

String or binary data would be truncated. The statement has been terminated.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: Saving information from .NET Listbox into SQL Server 2000

 
0
  #14
Jan 27th, 2006
Ok resolved, thanks alot campkev. !!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: Saving information from .NET Listbox into SQL Server 2000

 
0
  #15
Jan 29th, 2006
Campkev,

Once again thanks alot for your explanation and assistance with your postings. I am now stuck with another issue. Now since, i have saved the data into the table with commas. I would like to retrieve the data stored into the to a listbox which will display the seats that have already been booked. However, i am stuck with how can i remove the commas now and display it into the listbox as individual values.

I need to do this so i can disable buttons through the listbox so that tickets have been booked is unable to be rebooked

This is what i have written to retrieve it back to the listbox
Dim da As SqlDataAdapter = New SqlDataAdapter("Select SeatNum from Ticketing", Conn)
'Put user code to initialize the page here
Dim ds As DataSet = New DataSet
' Fill DataSet with the data
da.Fill(ds, "Ticketing")
' Set DataSource property of ListBox as DataSet’s DefaultView
listbox_seatsbooked.DataSource = ds.Tables("Ticketing").DefaultView

listbox_seatsbooked.SelectedIndex = 0
' Set Field Name you want to get data from
listbox_seatsbooked.DataTextField = "SeatNum"
' Bind the data
Page.DataBind()
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Saving information from .NET Listbox into SQL Server 2000

 
0
  #16
Jan 31st, 2006
Please use code tags. It is very hard to read posts that mix the message with the code. That's what the code tags are for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC