TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Scott G
NA
103
7.7k
Insert listbox contents to database
Sep 11 2018 8:53 AM
I am creating an application with several textboxes and a few listboxes. The first listbox is getting a list of games from a SQL table which contains ID, Name and Type columns. The listbox is display and value for the listbox is the Name. When clicking a button I can move the name from the first listbox to the second. Now I want to be able to write the ID of the items in the second listbox to another SQL table when saving.
The below code executes fine and inserts to the promo table. But when I try either adding a second insert statement (INSERT INTO promo_games(promo_ID, Game_ID) VALUES(@PID, @GameID)) to newPromo or creating a new string with a separate SQL insert for the listbox is when I run into problems. I am just not sure how to handle this to insert the multiple items and to take the ID from the item.
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["myConnStr"].ConnectionString;
SqlConnection misc = new SqlConnection(conn);
string newPromo = "INSERT INTO admin.promo (ID, masterId, Master, name, ...more text fields)"
"VALUES(@ID, @MasterID,@Master, @Name,...more text fields)";
SqlCommand insPromo = new SqlCommand(newPromo, misc);
insPromo.Parameters.AddWithValue("@ID", txtID.Text);
insPromo.Parameters.AddWithValue("@MasterID", txtMasterID.Text);
insPromo.Parameters.AddWithValue("@Master", chkMaster.Checked);
insPromo.Parameters.AddWithValue("@Name", txtName.Text);
...
...
misc.Open();
insPromo.ExecuteNonQuery();
misc.Close();
Reply
Answers (
1
)
How to know which event fires from start of windows form run
how to read the file line by line and inset into data base