📄 default.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonAdd_Click(object sender, EventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings["StudentsConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConn);
string strSql = "insert UserInfo(UserName,UserPwd) Values('" + TextBoxName.Text + "','" + TextBoxPwd.Text + "')";
//string strSql = string.Format("insert UserInfo(UserName,UserPwd) Values('{0}','{1}')", TextBoxName.Text, TextBoxPwd.Text);
SqlCommand cmm = new SqlCommand(strSql, conn);
//SqlCommand cmm = new SqlCommand();
//cmm.Connection = conn;
//cmm.CommandText = strSql;
try
{
conn.Open();
cmm.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
conn.Close();
}
}
protected void ButtonSearch_Click(object sender, EventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings["StudentsConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConn);
string strSql = "select ID,UserName,UserPwd from UserInfo where UserName='" + TextBoxSearchName.Text + "'";
SqlDataAdapter Sqlad = new SqlDataAdapter(strSql, conn);
DataSet ds = new DataSet();
conn.Open();
Sqlad.Fill(ds);
GridView2.DataSource = ds.Tables[0];
GridView2.DataBind();
//try
//{
// conn.Open();
// cmm.ExecuteNonQuery();
//}
//catch (Exception ex)
//{
// throw (ex);
//}
//finally
//{
// conn.Close();
//}
}
protected void ButtonDel_Click(object sender, EventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings["StudentsConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConn);
string strSql = "delete from UserInfo where UserName='" + TextBoxDel.Text + "'";
SqlCommand cmm = new SqlCommand(strSql, conn);
try
{
conn.Open();
cmm.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
conn.Close();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBoxNameUpd.Text = GridView1.Rows[GridView1.SelectedIndex].Cells[1].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -