我写的代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usi...
我写的代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;
namespace 号码管理系统
{
public partial class 新增管理员 : Form
{
public 新增管理员()
{
InitializeComponent();
}
private void send_Click(object sender, EventArgs e)
{
try
{
string Users = this.account_txt.Text;
string Pwd = this.pwd_txt.Text;
string rules = comboBox1.SelectedItem.ToString();
button1.Text = rules;
SqlConnection conn = new SqlConnection(@"Data Source=OVERSKY-PC\SQLEXPRESS;Initial Catalog=tel_mg;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select 1 from log_chck where account = '" + Users + "' and pwd='" + Pwd + "'", conn);
conn.Open();
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (Users == "")
{
MessageBox.Show("用户名为空");
}
else if (Pwd == "")
{
MessageBox.Show("密码为空");
}
else if (Convert.ToInt32(cmd.ExecuteScalar()) > 0)
{
MessageBox.Show("对不起!该账号已被设置,请重新设置!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
conn.Open();
string insert_sql;
insert_sql = "insert into log_chck values ('" + Users + ",'" + Pwd + "','" + rules + "')";
SqlCommand insertcmd = new SqlCommand(insert_sql, conn);
insertcmd.ExecuteNonQuery();
}
conn.Close();
}
catch
{
MessageBox.Show("对不起!操作失败!");
}
}
private void reset_Click(object sender, EventArgs e)
{
account_txt.Text = "";
pwd_txt.Text = "";
confirm_txt.Text = "";
}
}
}
数据存储用户信息的是log_chck表,字段值为account,pwd,identity。其中qccount,pwd都是来自用户填写的数据,即User,Pwd。indentity是用户在combox1中选择的数据。我不知道如何将这些数据插入数据中,具体的insert如何引用User,Pwd,combox1中的数据。
展开