0

i have a class for my sql duety, and have problem for my how could i do something like this

SqlParameter storedparam = new SqlParameter();
SqlParameter param1 = new SqlParameter("@userid", SqlDbType.BigInt);
param1.Value = "87";
SqlParameter param2 = new SqlParameter("@ip",SqlDbType.VarChar,40);
param2.Value = "192.168.1.1";
storedparam = param1 + param2;  //this parth have problem
Db myobject = new Db(myconection);
myobject.writestoredpro("nameofsotred",storedparam )
7
  • What is the parameter that your query expects? Commented Jan 10, 2013 at 12:21
  • Without knowing what type of API writestoredpro is expecting, that is pretty much impossible to answer, What is writestoredpro ? And what is Db ? Commented Jan 10, 2013 at 12:22
  • something like my simple example code Commented Jan 10, 2013 at 12:22
  • You are multiple BigInt and VarChar ? Commented Jan 10, 2013 at 12:22
  • @Mahyar your "simple example code" does nothing to explain what writestoredpro wants... Commented Jan 10, 2013 at 12:23

2 Answers 2

4

In the sql duety, take in params SqlParameter[] like so:

public void WriteStoredProcedure( string Query, params SqlParameter[] SqlParameters ) {
    // do it
}

For cases where you're defining a parameter and want to run it in one go, you can also define it like so:

SqlParameter storedParam = new SqlParameter("@ip",SqlDbType.Varchar,40) {
    Value = "192.168.1.1"
};
Sign up to request clarification or add additional context in comments.

Comments

1

the 'writetostoredpro' method would need to take a collection of SqlParameter objects, and then inside the method, you would need to iterate over the collection adding them to the SqlCommand.Parameters property. Take a look at this link : http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx of how to use the propertied, and SqlCommand class for an idea of what to do: http://msdn.microsoft.com/en-us/library/z4956bkc.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.