如何将用户输入的注册信息插入的数据库中
我写的代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingS...
我写的代码如下:
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中的数据。 展开
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中的数据。 展开
展开全部
我晕,竟然用中文命名名字空间!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
插入语句如下:
insert log_chck(account,pwd,identity)
values('"+Users+"','"+Pwd+"','"+rules+"')
你试试这样能不能..
insert log_chck(account,pwd,identity)
values('"+Users+"','"+Pwd+"','"+rules+"')
你试试这样能不能..
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询