I put the WebMethod script below in my .aspx page to connect to my database. However, it seems that I need to put “using System.Data” and “using System.SqlClient” somewhere to use ADO.NET. Can I use WebMethod in .aspx page (not.aspx.cs page) to connect to the database, and if so how should I use it?
<script runat="server">
[System.Web.Services.WebMethod]
public static void send()
{
SqlConnection con = new SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=Hello;Integrated Security=True");
SqlCommand cmd = new SqlCommand(queryString, con);
using (con)
{
con.Open();
cmd.ExecuteNonQuery();
}
}
</script>
u can try