I want to return json data when filled the webservice page?
public class WebService1 : System.Web.Services.WebService
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnn"].ConnectionString);
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string InsertData(string fname, string mname, string lname, string emailid, string password, string contactno, string hobby, string address, string countrycodenum)
{
cn.Open();
string data = "";
string insertquery = "insert into tblstudent(fname, mname, lname, emailid, password, contactno,hobby,address,countrycodenum)values(@fname,@mname,@lname,@emailid,@password,@contactno,@hobby,@address,@countrycodenum)";
SqlCommand cmd = new SqlCommand(insertquery, cn);
cmd.Parameters.AddWithValue("@fname", fname);
cmd.Parameters.AddWithValue("@mname", mname);
cmd.Parameters.AddWithValue("@lname", lname);
cmd.Parameters.AddWithValue("@emailid", emailid);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@contactno", contactno);
cmd.Parameters.AddWithValue("@hobby", hobby);
cmd.Parameters.AddWithValue("@address", address);
cmd.Parameters.AddWithValue("@countrycodenum", countrycodenum);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Console.WriteLine("Insert Successfully");
}
else
{
Console.WriteLine("Not Insert Successfully");
}
cn.Close();
return data;
}
}
}
x
I add this line for return the json data
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
when I inserted the data using webservice and click the Invoke Button of the webservice page then data is not display?
What I have tried:
I add this line for return the json data but json data is not displayed
[ScriptMethod(ResponseFormat = ResponseFormat.Json)