Hi,
I want to call a stored procedure and bind it to Gridview control... I am using datasets..How do i bind it?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mayur GujrathiPosted May 27, 2011, 7:04 AM
Kavita BPosted May 27, 2011, 6:52 AM
Mayur GujrathiPosted May 24, 2011, 9:34 AM
Query resolved?
Mayur GujrathiPosted May 24, 2011, 7:45 AM
private void fill_grid()
{
SqlConnection con = new SqlConnection(@"Data Source=AXIOMSERVER\SQL2005;" + "Initial Catalog=mydata; Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand;
cmd.CommandType=CommandType.StoreProcedure;
cmd.ComandText="Your Stored Procedure Name";
cmd.Connection=con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Details");
GridView1.DataSource = ds.Tables["Details"];
GridView1.DataBind();
}
Jiteendra SampathiraoPosted May 24, 2011, 7:24 AM
you will definitely get an idea...
http://www.c-sharpcorner.com/UploadFile/jitendra1987/3848/
Kavita BPosted May 24, 2011, 7:16 AM
private void fill_grid()
{
SqlConnection con = new SqlConnection(@"Data Source=AXIOMSERVER\SQL2005;" + "Initial Catalog=mydata; Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select distinct Name,Address,Phone from Details", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Details");
GridView1.DataSource = ds.Tables["Details"];
GridView1.DataBind();
}
I want to call the stored procedure here... In the line marked red what changes should i do to call the stored procedure?
My stored procedure which i want to call is :
create procedure select_details
@Name varchar(50),
@Address varchar(50),
@Phone varchar(50)
AS
Select Name,Address,Phone from Details
Praneeth KumarPosted May 24, 2011, 5:49 AM
gridViewName.Datasource=
gridViewName.Databind();
Aspx
Jiteendra SampathiraoPosted May 24, 2011, 5:38 AM
http://www.c-sharpcorner.com/UploadFile/jitendra1987/3848/
Suthish NairPosted May 24, 2011, 5:32 AM
DataGridView - Insert, Update, Delete and Retrieve records using stored procedure
Kiran KaralePosted May 24, 2011, 5:25 AM
//Declaration
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds; //
//
Write code for Click Event //
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Select_Procedure";
cmd.Connection = con;
con.Open();
SqlParameter tablename = new SqlParameter("@tablename",param);
cmd.Parameters.Add(tablename);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "Table");
GridView1.DataSource = ds;
GridView1.DataBind();
Gowtham manjuPosted May 24, 2011, 5:21 AM
copy and paste the coding below
create procedure as
create procedure proc_login
@un varchar(50),
@pwd varchar(50)
as
insert into login values(@un,@pwd)
where login in is the table name
in sourcecode of ur page write coding as
sqlconnection con=new sqlconnection("");
sqlcommand cmd=new sqlcommand("proc_login",con);//where proc_login is the procedure name u have created
cmd.command type=comandtype.storedprocedure;
cmd.parameters.add("@un",sqldbtype.varchar).value=textboxname.text;
cmd.parameters.add("@pwd",sqldbtype.varchar).value=textboxname.text;
con.open();
int rows=cmd.executenonquery();
con.close();
if(rows==1)
{
messagebox.show("inserted");
}else{messagebox.show("error");
}
the above is the sample source for using procedures u can implement it as u like
regards,
gowtham