dataset 修改数据库的一个数值。C#
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingS...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string conn="Data Source=(local);Initial Catalog=SimpleVote;trusted_connection=true";
SqlConnection ConnectionString;
ConnectionString = new SqlConnection("Data Source=(local);Initial Catalog=SimpleVote;trusted_connection=true");
string strsql ="SELECT [id], [password] ,[flag] FROM [User]";
SqlCommand cmd = new SqlCommand(strsql, ConnectionString);
ConnectionString.Open();
SqlDataReader rd = cmd.ExecuteReader();
//以下是自己写的,可能有不实际的地方。用dataset修改flag标志位
string string1 = "SELECT [flag] FROM [User]";
SqlDataAdapter da=new SqlDataAdapter (string1,conn);
DataSet ds = new DataSet();
da.Fill(ds, "User");
//rd.GetValue(0).ToString() 显示登录名
//rd.GetValue(1).ToString() 显示密码
//rd.GetValue(2).ToString() 是标志位
while (rd.Read())
{
if (rd.GetValue(0).ToString() == TextBox1.Text)
{
if (rd.GetValue(1).ToString() == TextBox2.Text)
{
string str=rd.GetValue(2).ToString();
if (str == "0")
{
Response.Redirect("Default.aspx");
}
else { Label1.Text = "您已经投过票!"; }
}
else
{
Label1.Text = "密码错误!";
}
}
else
{
Label1.Text = "用户名错误";
}
}
ConnectionString.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
}
id password flag
12 12 0
13 13 0
14 14 0
登录后flag修改成1,这是sql的数据库里的表 展开
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string conn="Data Source=(local);Initial Catalog=SimpleVote;trusted_connection=true";
SqlConnection ConnectionString;
ConnectionString = new SqlConnection("Data Source=(local);Initial Catalog=SimpleVote;trusted_connection=true");
string strsql ="SELECT [id], [password] ,[flag] FROM [User]";
SqlCommand cmd = new SqlCommand(strsql, ConnectionString);
ConnectionString.Open();
SqlDataReader rd = cmd.ExecuteReader();
//以下是自己写的,可能有不实际的地方。用dataset修改flag标志位
string string1 = "SELECT [flag] FROM [User]";
SqlDataAdapter da=new SqlDataAdapter (string1,conn);
DataSet ds = new DataSet();
da.Fill(ds, "User");
//rd.GetValue(0).ToString() 显示登录名
//rd.GetValue(1).ToString() 显示密码
//rd.GetValue(2).ToString() 是标志位
while (rd.Read())
{
if (rd.GetValue(0).ToString() == TextBox1.Text)
{
if (rd.GetValue(1).ToString() == TextBox2.Text)
{
string str=rd.GetValue(2).ToString();
if (str == "0")
{
Response.Redirect("Default.aspx");
}
else { Label1.Text = "您已经投过票!"; }
}
else
{
Label1.Text = "密码错误!";
}
}
else
{
Label1.Text = "用户名错误";
}
}
ConnectionString.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
}
id password flag
12 12 0
13 13 0
14 14 0
登录后flag修改成1,这是sql的数据库里的表 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询