Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

dataGridView help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gidi - 12 Oct 2007 17:42 GMT
Hi,

I have a dataGridView in my win Form, and i get some information from my
DataBase (sql) into a dataTable.

I tried and tried and i can't display my result in the dataGridView.

in addition, I also want to edit the columns (change the headr and size), i
know i can do it with the columns collection, but i need to bind each column
to a coulmn in my dataBase, and i don't know how to do it.

this is my code:

com = new SqlCommand();
           da = new SqlDataAdapter();
           // dt = new DataTable();

           //
           // com
           //

           this.com.CommandText = "[Get_Message_By_Person]";
           this.com.CommandType = System.Data.CommandType.StoredProcedure;
           this.com.Connection = m_mc.Get_dbcon().GetConn();
           this.com.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
false, ((System.Byte)(10)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));

           //
           // da
           //
           this.da.SelectCommand = this.com;

           System.Data.SqlClient.SqlParameter msg_to =
this.com.Parameters.Add(new System.Data.SqlClient.SqlParameter("@msg_to",
System.Data.SqlDbType.VarChar, 150));
           msg_to.Value = employees_cb.Text;

           da.Fill(msg_dt);

           msg_dgv.DataSource = msg_dt;

thanks,
Gidi.
Peter Bromberg [C# MVP] - 12 Oct 2007 18:25 GMT
The first thing I notice about your sample is that nowhere is the msg_dt
Datatable created before the Fill method is called. You need to have
DataTable msg_dt = new DataTable();
somewhere before you pass it into the Fill method. Some exception handling
would have also been helpful, as you would have seen the exception if you
caught it.
--Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com

> Hi,
>
[quoted text clipped - 42 lines]
> thanks,
> Gidi.
Gidi - 12 Oct 2007 22:40 GMT
Hi,

I've the DataTable msg_dt = new DataTable(); i just put it in the Initialze
part and not in this part of code, so i still have these 2 problems.

Thanks,
Gidi.

> The first thing I notice about your sample is that nowhere is the msg_dt
> Datatable created before the Fill method is called. You need to have
[quoted text clipped - 54 lines]
> > thanks,
> > Gidi.
bob clegg - 15 Oct 2007 11:40 GMT
Hi Gidi,
I usually declare a dataset which houses a data table
that has field names and types the same as the selected fields in the
sproc.
I ask the dataadapter to fill the dataset's table then
pass the dataset back to the datagridview.
i.e.
void LoadData
{
myTypedDataset ds = myDataFillingFunction();
myDataGridView.DataSource = ds;
myDataGridview.DataMember = ds.myDataTable.TableName;
}

myTypedDataset myDataFillingFunction()
{
Connection stuff and parameter stuff
myTypedDataset d = new myTypedDataSet();
da.Fill(d.myDataTable);//intellsense will show you the table
return d;
}

As Peter said exception handling will allow you to see if the SPROC is
happy with your handiwork.

hth
Bob

>Hi,
>
[quoted text clipped - 62 lines]
>> > thanks,
>> > Gidi.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.