web service select data

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
hi

How to choose data in stored procedures when use web service ?

1- stored procedures



ALTER proc [dbo].[select_message] (
@codeuser nvarchar(50),@active bit)
as
select top 1 * from message_tb where active=@active and codeuser=@codeuser
--add



2- web service Method

//get message
[WebMethod]
public DataTable Getmessage(string codeuser)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("select_message", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@active", SqlDbType.Bit).Value = true;
cmd.Parameters.Add("@codeuser", SqlDbType.NVarChar).Value = codeuser;

if (con.State != ConnectionState.Open)
{
con.Open();
}
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
adp.Fill(dt);


if (con.State == ConnectionState.Open)
{
con.Close();
}
}

}
return dt;
}



3- error when test select

1608843.png

Continue reading...
 
Back
Top