Hi,
you can go for dynamic SQL queries.
prepare the string like below.
string strQuery = "INSERT INTO TableName(";
int count =0;
foreach(object itemChecked in checkedListBox1.CheckedItems)
{
strQuery += itemChecked.ToString();
count++;
if(checkedListBox1.CheckedItems.Count > count)
strQuery += ",";
}
strQuery += ")VALUES(";
for(int i =0;i<checkedlistbox1.checkeditems.count; i++)
{
if(i != 0)
strQuery +=",";
strQuery += "Value " + i.ToString();
}
send that string to stored procedure and in the procedure execute the query like below.
EXEC(@Query)
refer links below for more on dynamic sql.
Execute Dynamic SQL commands in SQL Server[
^]
Dynamic SQL[
^]
hope it helps.