Posts Tagged ‘data source’

How to bind Combobox to a table field?

November 28, 2008

Binding ComboBox to a table using Stored Procedure

SqlDataAdapter da = new SqlDataAdapter(“StoredProcedureName”,Connection);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(new SqlParameter(“@Param1”, Value for @Param1));
DataSet ds = new DataSet( );
da.Fill(ds, “TableName”);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = “TableName”;

Binding ComboBox to a table using Command

Connection.Open();

SqlDataAdapter da = new SqlDataAdapter(“select Uname from Table1”, Connection);

DataSet ds = new DataSet( );

da.Fill(ds, “Table1”);
comboBox1.DataSource =ds.Tables[0];
comboBox1.DisplayMember = “Uname”;

Connection1.Close();

Udhaya

PiSquare Soft Solns

How to use DataGrid in C# .Net?

November 1, 2008

First place the DataGridView Control in the form.In the coding add the namespasce

using System.Data.SqlClient;

then initialize SqlConnection to ConnString as public (i.e)next to public Form1( ) {InitializeComponent( );}

SqlConnection con = new SqlConnection(“Your Connection String”);

DataSet ds;

Inside any event such as Form_load or button1_click add the code

SqlDataAdapter da=new SqlDataAdapter(“select * from table1”,con);

ds=new DataSet();

da.Fill(ds,”table1″);

dataGridView1.DataSource=ds;

dataGridView1.DataMember=”table1″;

By

Udhaya