.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Easy Web
Imran Ghani

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

how to do multiple binding in datagrid

Posted By: niaz     Posted Date: September 04, 2008    Points:2   Category :C#
hai friend i had a doubt

string t1, t2;
t1 = dataGridView1.CurrentCell.RowIndex.ToString();
t2 = dataGridView1.CurrentCell.ColumnIndex.ToString();
cmd = new SqlCommand("", conn);
cmd.CommandText = "select productname from adddata where billingcode='" + dataGridView1[int.Parse(t2), int.Parse(t1)].Value+"'";
//textBox1.Text = dataGridView1[0, 0].Value.ToString();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
// sqlDataAdapter1.Fill(adataset1, "adddata");
adp.Fill(ds, "adddata");

dataGridView1.DataBindings.Add(new Binding("datasource", ds , "adddata"));

this is my code to select some datas from the database and bound into a data grid

so my pblm is tat when execute the first time no problem when i select billing code from the datagrid and i can access the corresponding data from the database and bind to the grid but in second time when i select the billing code a pblm occur tat is multiple binding not allowed in the data grid .so how i can manage it ..... my code for taT is written above

i didnt have so much experience in dot net. now i passed my btech and looking for some job . so i do some small projects to know more in dot net .so pls help me

Author: Pankaj Mishra             
Posted Date: September 04, 2008     Points: 5   

Insted of this line of code


dataGridView1.DataBindings.Add(new Binding("datasource", ds , "adddata"));

Try this

dataGridView1.DataSource = ds;

Hope this will help you


Author: krishana singh             
Posted Date: October 16, 2010     Points: 5   

if (con.State == ConnectionState.Open)
string query = "select * from tblImg where Status='1'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend