一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Jquery+asp.net 检测账号是否已被注册的实例代码

时间:2010-07-12 编辑:简简单单 来源:一聚教程网

jquery+asp教程.net 检测账号是否已被注册的实例代码

<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="ajax_xml._default" %>










































 
websevic1.asmx.cs

 

using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.services;
using system.data;
using system.data.sqlclient;
using system.configuration;
using system.text;
using dal;
namespace ajax_xml
{
///


/// webservice1 的摘要说明
///

[webservice(namespace = "http://tempuri.org/")]
[webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]
[system.componentmodel.toolboxitem(false)]
// 若要允许使用 asp.net教程 ajax 从脚本中调用此 web 服务,请取消对下行的注释。
[system.web.script.services.scriptservice]
public class webservice1 : system.web.services.webservice
{
[webmethod]
public string helloworld()
{
return "hello,world!";
}
[webmethod]
public string userisexist(string userid)
{
string sql = string.format("select * from customers where firstname='" + userid+"'");
using (sqldatareader dr = sqlhelper.executesql(sql))
{
if (dr.read())
return "false";
else
return "true";
}
}
}
}

sqlheper.cs


using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.data;
using system.data.sqlclient;
using system.configuration;
namespace dal
{
///


/// 数据库教程操作类
///

public class sqlhelper
{
private static sqlconnection conn;
private static sqlcommand comm;
private static sqldatareader dr;
///
/// 打开数据库连接
///

public static void connopen()
{
try
{
conn = new sqlconnection(configurationmanager.connectionstrings["bbs"].connectionstring);
conn.open();
}
catch (exception e)
{
console.writeline( e.message);
}
}
///
/// 关闭数据库连接,释放资源
///

public static void connclose()
{
if (conn != null)
{
conn.close();
}
if (comm != null)
{
comm.dispose();
}
}
public static sqldatareader executesql(string sql)
{
sqlhelper.connopen();
comm = new sqlcommand(sql, conn);
try
{
dr = comm.executereader();
return dr;
}
catch (exception e)
{
throw e;
}
}
}
}

热门栏目