Hi all,

I'm newbe need your help. I have code:

public void Material_Load(object sender, EventArgs e)
        {
            SqlConnection con;
            SqlDataAdapter da;
            DataSet ds;
                                              
            con = new SqlConnection();
            con.ConnectionString = "Data Source=GOD_LOVE_ME;Initial Catalog=ProjetDB;Integrated Security=True";
            con.Open();

            da = new SqlDataAdapter("select * from Material", con);
            ds = new DataSet();
            da.Fill(ds);
            DG1.DataSource = ds;
            }

but.. I can't select row or column, can u help me chnge this code?

Thanks.

Set DataMember property with a name of table,

DG1.DataSource=ds;
DG1.DataSource="Material";

or

You may use,

DG1.DataSource=ds.Tables[0];

can't select or can't see,after datasource bind the data

DG1.DataSource=ds;DG1.DataSource="Material";DG1.DataSource=ds;
DG1.DataSource="Material";
DG1.DataBind();

When you say you cant see, do you mean the datagrid does not contain any values?

can't select or can't see,after datasource bind the data

DG1.DataSource=ds;DG1.DataSource="Material";DG1.DataSource=ds;
DG1.DataSource="Material";
DG1.DataBind();

In the above, your DataSource will contain the last object set:

DG1.DataSource=ds;DG1.DataSource="Material";DG1.DataSource=ds;

will result in:

DG1.DataSource=ds;

which is back to your original code...

Try:

DG1.DataSource=ds.Tables[0];

And, for programmatically selecting rows, use a currency manager:

// local to form...
                DataView dv;
                DataSet ds;
                CurrencyManager CM;


                    // in form's load after loading DataSet...
                    dv = new DataView(ds.Tables[0]);
                    CM = (CurrencyManager)dataGridView1.BindingContext[dv];
                    CM.Position = 1; // position the row pointer...

NOTE: I took the CurrencyManager code from a DataGrid (not DataGridView ) I had, so I'm not sure but I think it will work...I have to run and don't have time to test it.

Cheers!

thanks for help

but.. this is not run.... i don't know what happen?
maybe i'm forget something?

because when i write :

DG1.DataBind();

C# VS 2008 can't read this code, i can't using "DataBind()"
this is my using :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.Data.Sql;

thankyou for help

Sorry.. all

it's now work... because i kill my event and using

DG1.DataSource = "Material";

thank you everybody.. if any question i will asking again ;]

best regards,
martin

Sorry.. all
it's now work... because i kill my event and using

DG1.DataSource = "Material";

thank you everybody.. if any question i will asking again ;]

OK, for my own sanity and anyone else looking at this thread, what we really mean is (and correct me if I am wrong):

DG1.DataSource = ds;
    DG1.DataMember = "Material";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.