Use AddWithValue method, string para={"@eno","@ename","@edate"}; object val={11,"A","1-1-2002"}; System.Data.SqlClient. SqlConnection cn = new System.Data.SqlClient. SqlConnection(@""); System.Data.SqlClient.
SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); cmd. CommandText = "proc_name"; cmd. CommandType = CommandType.
StoredProcedure; cmd. Connection = cn; for(int i=0;iAddWithValue(parai, vali); } cn.Open(); cmd.ExecuteNonQuery(); cn.Close().
You need to do this: Sql command example: "SELECT * FROM YourTable WHERE FirstColumn = @YourParameterID;" To add a parameter for this command: Command.Parameters. Add(new SqlParameter("@YourParameterID", SqlDbType. Int).
Value = X).
Why not just use Parameters. AddWithValue? Seems a lot easier.... – marc_s Aug 31 '09 at 5:26.
I'm not an expert, but I guess you should name your parameters; so instead of just having an array of object, you should consider having an array of key-value pairs. Then, you should take a look at one of SqlParameter constructors: msdn.microsoft.com/en-us/library/system.....
You can also use an abbreviated version. ADO. NET will know it's a number and will insert the proper datatype if you do this: Command.Parameters.
Add(new SqlParameter("@YourParameterID", 4)); etc. Also, make sure you're not inserting a NULL into a NOT NULL data field, and is implicitly castable to type SqlParameter.
1 why not just use Parameters. AddWithValue? Seems a lot easier.... – marc_s Aug 31 '09 at 5:26.
Your SqlCommand wraps up the stored procedure. In order to call it, you will need to create an instance of a SqlParameter for each parameter that you pass into or get out of the stored procedure. You cannot just simply add your values - how would ADO.NET know which value to assign to which parameter?
Each SqlParameter contains things like: a name its datatype possibly restrictions (on size, length) and possibly a value So in your case, your statement should look something like this: SqlCommand Command = Connection.CreateCommand(); Command. CommandText = ProcedimientoAlmacenado; Command. CommandType = CommandType.
StoredProcedure; foreach (object X in Parametros) { SqlParameter param = new SqlParameter(); param. ParameterName = Parametros.Name; // you need to find a way to determine what DATATYPE the // parameter will hold - Int, VarChar etc. Param. SqlDbType = SqlDbType.Int; param.
Value = Parametros. Value; Command.Parameters. Add(param); } So, just adding values isn't going to work - you need to capture those parameters with their name, data type, length etc. And their values.
Marc.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.