Please see my code :

using System;
using System.Collection.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication1
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent(); 
		}
		
		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.DataMember = "customer";
			con1.Close();
		}
	}
}

What wrong whit my code???any mistake here...

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

commented: than you +1

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 :)

yeah..you're welcome :)

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.