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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Gowtham manju157 reputationPosted May 24, 2011, 1:21 AM EDT
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
Kiran KaraleRank #3,873 · 383 reputationPosted May 24, 2011, 1:25 AM EDT
//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();Suthish NairRank #92 · 22.8K reputationPosted May 24, 2011, 1:32 AM EDT
DataGridView - Insert, Update, Delete and Retrieve records using stored procedure
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted May 24, 2011, 1:38 AM EDT
http://www.c-sharpcorner.com/UploadFile/jitendra1987/3848/
Praneeth KumarRank #4,422 · 344 reputationPosted May 24, 2011, 1:49 AM EDT
gridViewName.Datasource=
gridViewName.Databind();
Aspx
Kavita B135 reputationPosted May 24, 2011, 3:16 AM EDT
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
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted May 24, 2011, 3:24 AM EDT
you will definitely get an idea...
http://www.c-sharpcorner.com/UploadFile/jitendra1987/3848/
Mayur GujrathiRank #666 · 3.6K reputationPosted May 24, 2011, 3:45 AM EDT
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();
}
Mayur GujrathiRank #666 · 3.6K reputationPosted May 24, 2011, 5:34 AM EDT
Query resolved?
Kavita B135 reputationPosted May 27, 2011, 2:52 AM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted May 27, 2011, 3:04 AM EDT