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 are three methods for displaying data in a syncfusion datagrid

843


What is ado.net full form?

760


List the 4 common ado.net namespaces?

889


What is sqldatasource?

719


Can we create Synonymns in MS Acess,My Sql Server,Sql Server? But iam we can create in oracle!

1893


Which architecture does Datasets follow?

815


Describe the disconnected architecture of ADO.NET’s data access model.

786


What are the different ado.net namespaces are available in .net?

769


What is sqldatareader in ado.net?

701


What are the difference between readonly vs. Const?

724


What are all the classes that are available in System.Data Namespace?

794


What is difference between datareader and dataadapter?

819


What is ado full form?

767


How to pass multiple tables in datasets simultaneously?

820


What we do with the object of ado.net dataset after using it?

735