Display Data on Datagrid

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 38
Reputation: ITKnight is an unknown quantity at this point 
Solved Threads: 1
ITKnight's Avatar
ITKnight ITKnight is offline Offline
Light Poster

Display Data on Datagrid

 
0
  #1
Apr 11th, 2008
Please see my code :
  1. using System;
  2. using System.Collection.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.SqlClient;
  9.  
  10. namespace WindowsApplication1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. private void cmdtam_Klik(object sender, EventArgs e)
  20. {
  21. string cstr;
  22. cstr = "data source=knight;initial catalog=latihan;uid=sa;pwd=sri";
  23. SqlConnection con1 = new SqlConnection(cstr);
  24. con1.Open();
  25. SqlCommand com1 = new SqlCommand();
  26. com1.Connection = con1;
  27. com1.CommandType = CommandType.Text;
  28. com1.CommandText = "select * from customer"
  29. DataSet ds1 = new DataSet();
  30. SqlDataAdapter adp1 = new SqlDataAdapter(com1);
  31. adp1.Fill(ds1,"customer");
  32. grd1.DataMember = "customer";
  33. con1.Close();
  34. }
  35. }
  36. }
What wrong whit my code???any mistake here...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Display Data on Datagrid

 
2
  #2
Apr 11th, 2008
I added one line code...see the red one :
private void cmdtam_Klik(object sender, EventArgs e)
		{
			string cstr;
			cstr = "data source=knight;initial catalog=latihan;uid=sa;pwd=sri";
			SqlConnection con1 = new SqlConnection(cstr);
			con1.Open();
			SqlCommand com1 = new SqlCommand();
			com1.Connection = con1;
			com1.CommandType = CommandType.Text;
			com1.CommandText = "select * from customer"
			DataSet ds1 = new DataSet();
			SqlDataAdapter adp1 = new SqlDataAdapter(com1);
			adp1.Fill(ds1,"customer");
			grd1.DataSource = ds1;
                        grd1.DataMember = "customer";
			con1.Close();
		}
your code not set data source of data grid with your dataset(ds1)...

Hope this helps
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 38
Reputation: ITKnight is an unknown quantity at this point 
Solved Threads: 1
ITKnight's Avatar
ITKnight ITKnight is offline Offline
Light Poster

Re: Display Data on Datagrid

 
0
  #3
Apr 11th, 2008
Originally Posted by Jx_Man View Post
I added one line code...see the red one :
private void cmdtam_Klik(object sender, EventArgs e)
		{
			string cstr;
			cstr = "data source=knight;initial catalog=latihan;uid=sa;pwd=sri";
			SqlConnection con1 = new SqlConnection(cstr);
			con1.Open();
			SqlCommand com1 = new SqlCommand();
			com1.Connection = con1;
			com1.CommandType = CommandType.Text;
			com1.CommandText = "select * from customer"
			DataSet ds1 = new DataSet();
			SqlDataAdapter adp1 = new SqlDataAdapter(com1);
			adp1.Fill(ds1,"customer");
			grd1.DataSource = ds1;
                        grd1.DataMember = "customer";
			con1.Close();
		}
your code not set data source of data grid with your dataset(ds1)...

Hope this helps
oh...i m missing that.
thanks jx_man for great helps and quick respond.
see you next thread
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Display Data on Datagrid

 
1
  #4
Apr 11th, 2008
yeah..you're welcome
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC