I wrote this code in win app :
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@';Data Source=.;Initial Catalog=MyDB;Integrated Security=True';);
SqlCommand cmd = new SqlCommand(';hi';, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
dataGridView1.DataSource = dr;//give data to gridview
// I dont know what should i write here to bind data
dr.NextResult();
}
and i dont know how can i bind data in win app , but in asp.net we can use this statement :gridview1.databind();I have written a store procedure in sql server, and i have connected the sqlserver to .net, ?
try here sqldatadaptor,dataset in place of datareader
u cant bind DGV1 with datareader.
dim ad as sqldataadaptor=new sqldataadaptor
ad.selectcommand=cmd
dim ds as dataset=new dataset
ad.fill(ds,';tablename';)
dataGridView1.DataSource = ds.tables(0)
whole code is
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@';Data Source=.;Initial Catalog=MyDB;Integrated Security=True';;)
cmd=new sqlcommand
cmd.connection=SqlConnection con
cmd.commandtext=';name of stored procedure';
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection.Open();
dim ad as sqldataadaptor=new sqldataadaptor
ad.selectcommand=cmd
dim ds as dataset=new dataset
ad.fill(ds,';tablename';)
dataGridView1.DataSource = ds.tables(0)
Any error . u can ask
No comments:
Post a Comment