TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gaurav Pal
NA
306
68.5k
Asp.net web service return json
Jul 27 2015 4:02 AM
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();
}
Reply
Answers (
9
)
paasing list object to web service
request to http-server