Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to add many items after scan them one by one from database into datatable


What I have tried:

public void CheckItem( string itemcode)
        {
            string constring = @"Data Source=.;Initial Catalog=pos;User id = sa;password=123";
            SqlCommand objCmd = new SqlCommand();
            objCmd.Parameters.Clear();
            using (SqlConnection objCnn = new SqlConnection(constring))
            {
                objCnn.Open();
                using (objCmd = objCnn.CreateCommand())
                {
                    objCmd.CommandType = CommandType.Text;
                    objCmd.CommandText = "SELECT  * FROM Items where Item_Code=@Item_Code";
                    objCmd.Parameters.Add(new SqlParameter("@Item_Code", itemcode));
                  
                    SqlDataReader myreader = objCmd.ExecuteReader();
                    DataTable dt = new DataTable();
                    dt.Load(myreader);
                     decimal sumprice=0;
                    if (dt.Rows.Count <= 0)
                     
// here i want to add new item into datatable , after that bind the new item with items that i added before 
 
 
                    dt = objDT.NewRow();
                    dt.Columns.Add("", typeof(decimal));
                  
                    dataGridView1.DataSource = dt;
 
                   
 
 
                }
            }
        }
Posted
Updated 20-Aug-17 21:20pm
Comments
Richard Deeming 21-Aug-17 11:42am    

1 solution

try this,

DataRow dr=new DataRow();

dr["name of the column where you want add data"]="add value";

dt.Rows.add(dr);

DataGridView1.DataSource=dt;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900