| | |
Display Data on Datagrid
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
Please see my code :
What wrong whit my code???any mistake here...
C# Syntax (Toggle Plain Text)
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(); } } }
I added one line code...see the red one :
your code not set data source of data grid with your dataset(ds1)...
Hope this helps
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();
}Hope this helps
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
•
•
I added one line code...see the red one :
your code not set data source of data grid with your dataset(ds1)...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(); }
Hope this helps
thanks jx_man for great helps and quick respond.
see you next thread
yeah..you're welcome
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
![]() |
Other Threads in the C# Forum
- Previous Thread: Is there a way to not to use a data base
- Next Thread: how to import a csv file to sql server 2005 database table using C#
| Thread Tools | Search this Thread |
.net access algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom database databasesearch datagrid datagridview datagridviewcheckbox dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum equation event excel file form format formatting forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install interface java label list listbox mandelbrot math mouseclick mysql namevaluepairs operator path photoshop picturebox pixelinversion post powerpacks programming property radians regex remote remoting resource restore richtextbox server sleep soap socket sql statistics stream string table text textbox thread time timer update usercontrol validation visualstudio wait webbrowser windows winforms working wpf xml






