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 HawaldarPosted Jun 16, 2021, 4:20 AM
Guest UserPosted Jun 16, 2021, 9:06 AM
Guest UserPosted Jun 16, 2021, 7:09 AM
Guest UserPosted Jun 16, 2021, 6:46 AM
Jignesh Kumar,
Rajanikant Hawaldar thank you both of you
Jignesh KumarPosted Jun 16, 2021, 5:51 AM
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 UserPosted Jun 14, 2021, 5:38 PM
Rajanikant HawaldarPosted Jun 14, 2021, 10:40 AM
Guest UserPosted Jun 14, 2021, 10:28 AM
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 HawaldarPosted Jun 14, 2021, 5:27 AM