HOW TO RETRIEVE RECORD IN ASP.NET

Posted by Parthibansk under ASP.NET on 8/17/2012 | Points: 10 | Views : 735 | Status : [Member] | Replies : 3
i created a stored proc for retrieving details of particular record by id as input.. it works fine in sqlsever..

but i couln't able to retrive record in asp.net..

CREATE PROC [dbo].[T1GETDET]
@ID INT
AS
SELECT NAME,OTHERS FROM TABLE1 WHERE ID=@ID

here is the asp.net code...


string strcon = "Data Source=PARTHI-PC\\SQLEXPRESS;Initial Catalog=EMPLOYEE;Integrated Security=True";
SqlConnection con = new SqlConnection(strcon);A
SqlCommand com = new SqlCommand("T1GETDET", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("ID", TextBox1.Text);
com.Parameters.Add(p1);
con.Open();
com.ExecuteNonQuery();
con.Close();




Responses

Posted by: Ranjeet_8 on: 8/17/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this

System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd = new System.Data.SqlClient.SqlCommand("GetallLatestNews", YourConnectionString);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ParametersName", YourParametersValue));
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();


Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/17/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Parthibansk
plz Mark As Answer, if post helps you.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dhirajkumar on: 8/18/2012 [Member] Starter | Points: 25

Up
0
Down
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "StoredProcedureName";
cmd.Parameters.AddWithValue("Parametername", Value);

cmd.Connection = con;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand =cmd;
da.Fill(ds);


Dhiru

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response