Insert using checkedlistbox
i need to insert multiple items using checkedlistbox in c# and sql 2005.please give code and insert sp
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ankur JainRank #2,475 · 567 reputationPosted Aug 12, 2014, 1:13 AM EDT
code for get selected item from checkbox list and save using store procedure...
now you can pass rightSelectedItems as parameter in your procedure...
create procedure sp_insertCheckboxItem
@Item nvarchar(250)=null
as
begin transcation
insert into tablename (columnname) values(@item)
commit;
end
please don't forget to mark it as answer if it's helpful
Dipankar BiswasRank #992 · 2K reputationPosted Aug 12, 2014, 1:17 AM EDT
Sqlconnection con=new Sqlconnection();
con.open();
con.Connectionstring="Data Source=PHANNY-PC\PHANNY; Initial Catalog=db_stuRegisterPay; Integrated Security=SSPI";
string query="insert into Persons_info(perID, latinName, gender, dob, pob, phone, passport, curAdd, status) values('" + txtID.Text + "','" + txtLatinName.Text + "','" + cbGender.Text + "'" + dTPdob.Text + txtPob.Text + "','" + txtPhone.Text + "','" + txtPassport.Text + "'" + txtCurAdd.Text + "'" + cbStatus.Text + " )";
SqlCommand cmd=new SqlCommand(query,con);
cmd.ExecuteNonQuery();
MessageBox.show("Saving is done!");
Now your sp in sql..example.
C# Code.........example..
try
{
sqlConnection = new SqlConnection(dbConnectionString);
SqlCommand command = new SqlCommand("sp_Test", sqlConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text;
command.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text;
sqlConnection.Open();
return command.ExecuteNonQuery();
sqlConnection.Close();
}
catch (SqlException ex)
{
Console.WriteLine("SQL Error" + ex.Message.ToString());
return 0;
}
you are use checkbox.... so only change...
command.Parameters.Add("@Id", SqlDbType.VarChar).Value = checkbox1.Text;