SQL Query
use Maintenance
INSERT INTO tbl_asigncharges (CHARGES, VALUEofCHARGES) select TYPEOFCHARGES,VALUEofCHARGES from tbl_charges

this table apply in to this query
C# Code
try
{
foreach (var item in checkedListBox1.CheckedItems)
{
if (!checkedListBox2.Items.Contains(item.ToString()))
{
checkedListBox2.Items.Add(item);
string i = (item.ToString());
if (MessageBox.Show("Assgned", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
{
sqlcon.Open();
string query = "INSERT INTO tbl_asigncharges (SN,CHARGES,VALUEofCHARGES) VALUES ('" + Convert.ToInt32(regno.Text) + "','" + item.ToString() + "','" + Convert.ToInt32(i) + "')";
SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
sda.SelectCommand.ExecuteNonQuery();
sqlcon.Close();
}
}
}
}
catch(Exception ex)
{
MessageBox.Show("Error" + ex);
}

code try in C# windows Form application

Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jun 16, 2021, 12:20 AM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jun 14, 2021, 1:27 AM EDT
Guest UserRank #1,881 · 787 reputationPosted Jun 16, 2021, 2:46 AM EDT
Jignesh Kumar,
Rajanikant Hawaldar thank you both of you
Guest UserRank #1,881 · 787 reputationPosted Jun 14, 2021, 6:28 AM EDT
I have 2 table 1st tbl_charges 2nd tbl_assigncharges
1st table pickup 2 value form tbl_charges ("TYPEOFCHARGES","VALUEofCHARGES") than i select this 2 colums value than assign in tbl_assigncharges ("CHARGES","VALUEofCHARGES") save the value
Edit this Query
string query = "INSERT INTO tbl_asigncharges (SN,CHARGES,VALUEofCHARGES) Select (TYPEOFCHARGES,VALUEofCHARGES) From tbl_charges ('" + Convert.ToInt32(regno.Text) + "','" + item.ToString() + "','" + Convert.ToInt32(i) + "')";
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jun 14, 2021, 6:40 AM EDT
Guest UserRank #1,881 · 787 reputationPosted Jun 14, 2021, 1:38 PM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Jun 16, 2021, 1:51 AM EDT
Hi,
Here issue is, You are trying to insert 3 column in you insert query and select query have only two column.
when you use like this you should have same number of column with same datatype for column. SN Column make identity Column which insert as auto increment.
Guest UserRank #1,881 · 787 reputationPosted Jun 16, 2021, 3:09 AM EDT
Guest UserRank #1,881 · 787 reputationPosted Jun 16, 2021, 5:06 AM EDT