I am using below code for my web service. I want return value in json. but this code return value in XML format only.
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public bool login(string uname, string pwd)
{
//SqlConnection con = new SqlConnection();
//SqlCommand cmd = new SqlCommand();
//con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
//SqlDataAdapter da = new SqlDataAdapter("select * from UserList where UserName ='" + uname + "' and password='" + pwd + "' ", con);
//DataSet ds = new DataSet();
//da.Fill(ds);
//return ds;
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.CommandText = "select * from UserList where UserName=@username and Password=@pwd";
cmd.Connection = con;
cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value = uname;
cmd.Parameters.Add("@pwd", SqlDbType.VarChar, 50).Value = pwd;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read() == true)
{
return true;
}
else
{
return false;
}
con.Close();
}
9 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raja TPosted Jul 29, 2015, 1:18 AM
Gaurav PalPosted Jul 29, 2015, 1:11 AM
Raja TPosted Jul 27, 2015, 7:40 AM
Gaurav PalPosted Jul 27, 2015, 6:24 AM
Manas MohapatraPosted Jul 27, 2015, 6:21 AM
Gaurav PalPosted Jul 27, 2015, 6:14 AM
Raja TPosted Jul 27, 2015, 5:52 AM
Raja TPosted Jul 27, 2015, 5:51 AM
Manas MohapatraPosted Jul 27, 2015, 5:19 AM