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.

Edited 7 Years Ago by __avd: Use [code] tags to wrap your source code.

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();

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

Edited 7 Years Ago by __avd: Added code tags. Encase your code in: [code] and [/code] tags.

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

Edited 7 Years Ago by __avd: Added code tags. Encase your code in: [code] and [/code] tags.

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";
This article has been dead for over six months. Start a new discussion instead.