本文介绍了如何以json格式输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好........

hi all........

[WebMethod]
 [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string Inserttblval(string UserName, int CountryId, int IsActive)
{
int rowsInserted;
SqlConnection conn = new SqlConnection("Data Source=SREENI\\SQLEXPRESS;Initial Catalog=TestDB;User ID=sa;Password=sa123");
string sql = string.Format(@"INSERT INTO [TestDB].[dbo].[Table_1] ([CountryId],[UserName],[IsActive]) VALUES ({0},'{1}',{2})", CountryId,UserName, IsActive);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
conn.Open();
rowsInserted = cmd.ExecuteNonQuery();
conn.Close();
cmd = null;
return string.Format("CountryId,UserName, IsActive");
}









错误是



错误3找不到类型或命名空间名称'ScriptMethodAttribute'(您是否缺少using指令或程序集引用?)E:\mine\webserviceasp.net1 \\ \\ App_Code \ WebService.cs 39 5 webserviceasp.net1





error is

Error3The type or namespace name 'ScriptMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)E:\mine\webserviceasp.net1\App_Code\WebService.cs395webserviceasp.net1

推荐答案

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]






after

[WebMethod]





ie。





ie.

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Inserttblval(string UserName, int CountryId, int IsActive)
{


}



这篇关于如何以json格式输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 11:40