Call a stored procedure from ado.net and pass parameter to it ?

Answer Posted / dinesh gupta

string
ConnectionString= "server="+DatabaseSrvr+";database="+Datab
aseNam+";user id="+DatabaseUsr+";password="+DatabasePass
;

Sqlconnection Cn = new SqlConnection(ConnectionString);
Cn.Open();

SqlCommand cmd = new SqlCommand("PROCNAME", Cn);

cmd.CommandType = CommandType.StoredProcedure;

SqlParameter p = new SqlParameter();

p = new SqlParameter();
p.ParameterName = "@parameter1";
p.SqlDbType = SqlDbType.VarChar;
p.Size = 10;
p.Value = "abc";
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);

p = new SqlParameter();
p.ParameterName = "@parameter2";
p.SqlDbType = SqlDbType.Int;
p.Value = Convert.ToInt16(textbox.text);
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);


cmd.ExecuteNonQuery();

Is This Answer Correct ?    8 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of Dataview?

568


What is a datareader object?

571


Which object is used to add relationship between two Datatables?

567


Which method is used to sort the data in ADO.Net?

1497


What are the namespaces used in ado.net for data access?

474






What is data reader in ado.net?

490


What is the use of SqlCommand object?

633


If we are not returning any records from the database, which method is to be used?

732


Which is faster datareader or dataadapter?

517


What is concurrency? How will you avoid concurrency when dealing with dataset? (One user deleted one row after that another user through his dataset was trying to update same row. What will happen? How will you avoid the problem?)

574


What is the difference between Optimistic and Pessimistic locking?

535


How to add an aggregate column?

523


What is the difference between dataset and datatable?

478


What is csdl entity framework?

544


Explain executenonquery?

547