| | |
Saving information from .NET Listbox into SQL Server 2000
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2006
Posts: 275
Reputation:
Solved Threads: 11
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.
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.
•
•
Join Date: Jun 2005
Posts: 50
Reputation:
Solved Threads: 0
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.
Server Error in '/WebApplication5' Application.
--------------------------------------------------------------------------------
String or binary data would be truncated. The statement has been terminated.
•
•
Join Date: Jun 2005
Posts: 50
Reputation:
Solved Threads: 0
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()
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()
![]() |
Similar Threads
- Freelance Web designer PHP, MySQL, ASP, SQL Server 2000 (Post your Resume)
- Developing SQL Server 2000 (MS SQL)
- SQL Server 2000 Help (MS SQL)
- SQL SERVER 2000 Login failure in ASP.NET (ASP.NET)
- Query conversion from Sybase to MS SQL Server 2000 (MS SQL)
Other Threads in the ASP.NET Forum
- Previous Thread: SqlDataAdapter bind to a listbox
- Next Thread: Bug? ToggleButton problem in toolbar for VC++.NET
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances application asp asp.net beginner box browser businesslogiclayer button c# cac checkbox child class compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form gridview gudi iis image javascript list listbox menu mouse mssql nameisnotdeclared news novell numerical opera order parent problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security select serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview typeof validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xsl






