以下是一个简单的ASP.NET脚本示例,该脚本使用C#语言编写,实现了一个简单的用户登录功能。请注意,这个示例假设你已经有一个名为"Users"的数据库表,其中包含"Username"和"Password"字段。
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1 // 你的项目名称可能与此不同,请根据实际情况修改
{
public partial class Login : Page // 你的页面名称可能与此不同,请根据实际情况修改
{
protected void Page_Load(object sender, EventArgs e) // Page_Load事件处理程序,每次页面加载时都会执行
{
} // Page_Load事件处理程序结束 } public void btnLogin_Click(object sender, EventArgs e) // 按钮点击事件处理程序,点击登录按钮时会执行 { string username = txtUsername.Text; string password = txtPassword.Text; SqlConnection conn = new SqlConnection("你的连接字符串"); try { conn.Open(); string sql = "SELECT COUNT(*) FROM Users WHERE Username='" + username + "' AND Password='" + password + "'"; SqlCommand cmd = new SqlCommand(sql, conn); int result = (int)cmd.ExecuteScalar(); if (result == 1) { Response.Write("登录成功!"); } else { Response.Write("用户名或密码错误!"); } } catch (Exception ex) { Response.Write("数据库连接错误:" + ex); } finally { conn.Close(); } } } } ```
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>登录</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">
</script>
</head>
<body>
<!--<h1>helloworld</h1>-->
<div class="outerdiv">
<div class="innerdiv">
<input type="text" id="username" name="username"/>
<input type="text" id="pwd" name="pwd" />
<input type="button" value="提交" οnclick="javascript:login()"/>
</div>
<div id="demo"></div>
</div>
</body>
</html>
以下可实现增删改查效果