Reputation: 9
I have three dropdownlist which values are to be inserted in one particular field in the database. But i am new to ASP.
This are my following codes:
Dim strConn = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim myConn As New SqlConnection(strConn)
Dim cmd = "INSERT INTO [IndividualWorkout] (WorkoutProgramName, WorkoutProgramPosted, WorkoutProgramDesc, IndividualWorkoutName, IndividualWorkoutTips, TimingID) VALUES (@WorkoutProgramName, @WorkoutProgramPosted, @WorkoutProgramDesc, @IndividualWorkoutName, @IndividualWorkoutTips, @TimingID)"
Dim myCmd As New SqlCommand(cmd, myConn)
myCmd.Parameters.AddWithValue("@WorkoutProgramName", TextBox1.Text)
myCmd.Parameters.AddWithValue("@WorkoutProgramPosted", TextBox2.Text)
myCmd.Parameters.AddWithValue("@WorkoutProgramDesc", TextBox3.Text)
myCmd.Parameters.AddWithValue("@IndividualWorkoutName", TextBox4.Text)
myCmd.Parameters.AddWithValue("@IndividualWorkoutTips", TextBox5.Text)
myCmd.Parameters.AddWithValue("@TimingID", DropDownList4.SelectedValue.ToString())
myCmd.Connection = myConn
myConn.Open()
myCmd.ExecuteNonQuery()
myConn.Close()
Could anyone guide me/help me with the editing of the following code so that the 3 dropdownlist values which were selected will go in the TimingID.
Thanks
Upvotes: 0
Views: 2879
Reputation: 2849
If you want to concatenate the values, you can do it like this.
string s = DropDownList4.SelectedValue.ToString() + "|"
+ DropDownList5.SelectedValue.ToString() + "|"
+ DropDownList6.SelectedValue.ToString();
myCmd.Parameters.AddWithValue("@TimingID", s);
Then you will have to parse out the 3 values when you retrieve the data from that field with a .Split() or similar function.
Just as a note, it seems odd to have an ID field use concatenated strings. I'm assuming this field requires uniqueness, which seems at risk by using a combination of dropdown values. Do you have that covered?
Upvotes: 1