bit parameter problem
-
i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks
-
i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks
What is the error that is thrown?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
All the world's a stage, And all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts... --William Shakespeare -
What is the error that is thrown?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
All the world's a stage, And all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts... --William Shakespeare -
i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks
-
i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks
Mr.Kode wrote:
checkDone.CommandType = CommandType.Text;
This should be
checkDone.CommandType = CommandType.StoredProcedure;
You're creating output parameters so they won't take input. You can make themInputOutput
parameters to take values and then they can alter them.Mr.Kode wrote:
bool mybool=bool.Parse(comp.Value).ToString();//error here
This line of code has multiple errors.
comp.Value
is object andParse
takes astring
parameter.comp.Value
isobject
and has not been set. Another error in this line is that after you "parse" tobool
, you're usingToString()
and assigning it tobool
:wtf: You retrieve values from the output parameters after the command has been executed. And it would bebool mybool = (bool)comp.Value;
The same for the other SqlParameter.Mr.Kode wrote:
checkDone.ExecuteScalar();
Why ExecuteScalar? Use ExecuteNonQuery if you're not retrieving a value. And this question should have been asked in the SQL / ADO / ADO.NET forum :)
Eslam Afifi