這是寫在類文件Delete.cs的代碼,我想下[的WebMethod]如何調用在類文件中定義的aspx.cs頁面上的功能
namespace Bootstrap
{
public class DeleteData
{
public static string DeleteData(int rollno)
{
string msg = string.Empty;
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spDeleteData", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Parameters.AddWithValue("@RollNo", rollno);
int i = cmd.ExecuteNonQuery();
con.Close();
if (i == 1)
{
msg = "true";
}
else
{
msg = "false";
}
}
return msg;
}
}
來訪問WebForm1.aspx的驗證碼
}
在我WebForm1.aspx的我把它稱爲這樣
[WebMethod]
DeleteData delete = new DeleteData();
delete.DeleteData(int rollno);
他們都使用相同的命名空間,我的Delete.cs是在App_Code文件夾中,但它給編譯時錯誤。 請幫忙
對不起,類文件名是DeleteData.cs –