Wednesday, December 17, 2008

SqlParameter

Case 1
SqlParameter[] osqlParam = new SqlParameter[2];

osqlParam[0] = new SqlParameter("@FromCity", SqlDbType.VarChar);
osqlParam[0].Value = _objTubeMap.fromStation;

osqlParam[1] = new SqlParameter("@ToCity", SqlDbType.VarChar);
osqlParam[1].Value = _objTubeMap.toStation;

return SQLHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, "GetStations", osqlParam);


Case2



string[] paramsNames = new string[2] { "@PostTitle", "@PostBody" };
string[] values = new string[2] { TextBox1.Text, Body };
SqlParameter[] parameters = new SqlParameter[2];

for (int i = 0; i < paramsNames.Length; i++)
{
parameters[i] = new SqlParameter();
parameters[i].ParameterName = paramsNames[i];
parameters[i].Value = values[i];
}

No comments: