How to get record by using ID
-
I have created a web form,but i have small problem,i need to retreive records from database according to ID which i given in the form in text box,i have created the StoredProcedure for that one its retreive data and i put where fieldname=@ID. When i'm using datagrid or GridView this will not occour,but i need to do in using text box.Please help me to do this Thank You
-
I have created a web form,but i have small problem,i need to retreive records from database according to ID which i given in the form in text box,i have created the StoredProcedure for that one its retreive data and i put where fieldname=@ID. When i'm using datagrid or GridView this will not occour,but i need to do in using text box.Please help me to do this Thank You
What is the question ? You need to write the SQL, which is basically select * from tbl where fieldname = id. Sounds like you did that. So, you get the id from the textbox, and pass it to the proc, set your datasource with the result, and databind.
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
What is the question ? You need to write the SQL, which is basically select * from tbl where fieldname = id. Sounds like you did that. So, you get the id from the textbox, and pass it to the proc, set your datasource with the result, and databind.
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
Ok but how do i pass my text value into StoredProcedure and i'm using DataReaders. Note-:Can i use SqlParameter for this one,if yes,how to do that.
-
I have created a web form,but i have small problem,i need to retreive records from database according to ID which i given in the form in text box,i have created the StoredProcedure for that one its retreive data and i put where fieldname=@ID. When i'm using datagrid or GridView this will not occour,but i need to do in using text box.Please help me to do this Thank You
Hi, first write one storedProc for Select data from DB with ID, Here is the Stored Procedure . Create Procedure nameofStoredProcedure ( @ID ) AS select * from table where id=@ID ADO.NEt code SqlConnection Con=new SqlConnection("userid="";databse=""; password=""); con.Open(); SqlCommand cmd=new SqlCommand("nameofStroredProcedure",con); cmd.CommandType=CommandType.StoredProcedure; cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text; SqlDataAdapter da=new SqlDataAdapter(); da.selectCommand=cmd; da.fill(ds,"tablename"); con.Close(); i hope this will helpful for u, try onces. WINNING IS NOT OUR DREAM,IT'S A HABIT HAVE A NICE DAY
-
Ok but how do i pass my text value into StoredProcedure and i'm using DataReaders. Note-:Can i use SqlParameter for this one,if yes,how to do that.
SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@", SqlDbType.NVarChar, 50); param[0].Direction == ParameterDirection.InputOutput; param[0].Value=; //Add the parameters to the command object objcommand.Parameters.Add(param); objcommand.CommandType=CommandType.StoreProcedure; objcommand.Connection=; objcommand.Command="Stored Proc Name"; objcommand.ExecuteNonQuery();
Kiran Kumar.CH (MCP)
-
Hi, first write one storedProc for Select data from DB with ID, Here is the Stored Procedure . Create Procedure nameofStoredProcedure ( @ID ) AS select * from table where id=@ID ADO.NEt code SqlConnection Con=new SqlConnection("userid="";databse=""; password=""); con.Open(); SqlCommand cmd=new SqlCommand("nameofStroredProcedure",con); cmd.CommandType=CommandType.StoredProcedure; cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text; SqlDataAdapter da=new SqlDataAdapter(); da.selectCommand=cmd; da.fill(ds,"tablename"); con.Close(); i hope this will helpful for u, try onces. WINNING IS NOT OUR DREAM,IT'S A HABIT HAVE A NICE DAY
dornala wrote:
Create Procedure nameofStoredProcedure ( @ID )
Incorrect syntax - you need to specify the datatype
dornala wrote:
SqlConnection Con=new SqlConnection("userid="";databse=""; password="");
Incorrect syntax - check your quotes
dornala wrote:
cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10));
Incorrect syntax - it should be
cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.VarChar,10));
-
dornala wrote:
Create Procedure nameofStoredProcedure ( @ID )
Incorrect syntax - you need to specify the datatype
dornala wrote:
SqlConnection Con=new SqlConnection("userid="";databse=""; password="");
Incorrect syntax - check your quotes
dornala wrote:
cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10));
Incorrect syntax - it should be
cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.VarChar,10));
J4amieC wrote:
Incorrect syntax - it should be cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.VarChar,10));
Well actually it should be cmd.Parameters.Add(new SqlParameter("@ID",SqlDbType.VarChar,10)); :P Also instead of using
cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text;
as described in the previous post, it would be much easier to use:cmd.Parameters.Add("@ID", textbox1.Text);
(AddWithValue in 2.0) Just my daily cup of being a smartass. -
Hi, first write one storedProc for Select data from DB with ID, Here is the Stored Procedure . Create Procedure nameofStoredProcedure ( @ID ) AS select * from table where id=@ID ADO.NEt code SqlConnection Con=new SqlConnection("userid="";databse=""; password=""); con.Open(); SqlCommand cmd=new SqlCommand("nameofStroredProcedure",con); cmd.CommandType=CommandType.StoredProcedure; cmd.parameter.add(new Sqlparameter("@ID",SqlDbType.Varchar(10)); cmd.parameter[0].value=textbox1.text; SqlDataAdapter da=new SqlDataAdapter(); da.selectCommand=cmd; da.fill(ds,"tablename"); con.Close(); i hope this will helpful for u, try onces. WINNING IS NOT OUR DREAM,IT'S A HABIT HAVE A NICE DAY
Hi Thank you freind Its working fine.