c#链接数据库源代码(图书借阅系统)

/// MainForm/
/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2017/12/20 星期三
 * Time: 下午 6:57
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
namespace library
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}


        private void button1_Click_1(object sender, EventArgs e)
        {
            String conn_String = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_String);
            conn.Open();
            //cmd 是判断数据库是否有查到值
           // SqlCommand cmd = new SqlCommand();
            //cmd.Connection = conn;
           // String string_select = "select count(*) from login where  name='"+textBox1.Text+"' and password='"+textBox2.Text+"'";
            //cmd.CommandText=string_select;
            //本想通过da 来查询admin的来判断管理员的
            //SqlDataReader da = cmd.ExecuteReader();
            String string_select_admin = "select * from user_info where  account='" + textBox1.Text + "' and password='" + textBox2.Text + "'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select_admin,conn);
            DataSet ds = new DataSet();
            da.Fill(ds,"login");


            if (ds.Tables[0].Rows.Count != 0)
            {
                 //MessageBox.Show("登陆成功");
                 if (ds.Tables[0].Rows[0]["user_rank"].ToString()=="0")
                 {
                     From_user f_u = new From_user();
                     
                     f_u.Show();
                     f_u.Txt = textBox1.Text;//给的是account 
                 }
                 else if (ds.Tables[0].Rows[0]["user_rank"].ToString() == "1" || ds.Tables[0].Rows[0]["user_rank"].ToString() == "2" || ds.Tables[0].Rows[0]["user_rank"].ToString() == "3")
                 {
                     From_admin f_a = new From_admin();
                     f_a.Show();
                     
               }
            }else {
                MessageBox.Show("登陆失败");
            }
           
            conn.Close();
        }










        private void button2_Click_1(object sender, EventArgs e)
        {
            Form_user_create f_u_c = new Form_user_create();
            f_u_c.Show();
        }
        private void label2_Click(object sender, EventArgs e)
        {


        }


        private void textBox2_TextChanged(object sender, EventArgs e)
        {


        }


       


       
}
}




















/// form_admin///
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace library
{
    public partial class From_admin : Form
    {
        public From_admin()
        {
            InitializeComponent();
        }
void TabPage1Click(object sender, EventArgs e)
{

}








        private void button1_Click(object sender, EventArgs e)
        {
            string shuhao = "";
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            String string_date = DateTime.Now.ToLongDateString().ToString();


            ///
            shuhao = textBox1.Text;
            String string_select = "select * from books where book_num='" + shuhao + "' ";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "user_info_num");


            if (ds.Tables[0].Rows.Count != 0)
            {
                MessageBox.Show("书号已存在");
            }
            else
            {










                ///
                String string_insert = "insert into books (book_num,book_name,book_author,book_class,book_press,book_press_data,book_price) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + string_date + "','" + textBox6.Text + "')";


                SqlCommand cmd = new SqlCommand(string_insert, conn);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("添加成功");
                }
                conn.Close();






            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
             String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            String string_select = "select * from books where book_num='" + textBox7.Text + "'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "book_borrow");




            if (ds.Tables[0].Rows.Count != 0)
            {
                //DELETE FROM 表名称 WHERE 列名称 = 值
                String string_delete = "delete  from books where book_num='" + textBox7.Text + "'";
                SqlCommand cmd = new SqlCommand(string_delete, conn);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("删除成功");
                }
            }
            else {
               MessageBox.Show("没有找到被删除的书");
            }
            conn.Close();
        }


        private void button4_Click(object sender, EventArgs e)
        {
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            String string_select = "select * from books where book_num='" + textBox8.Text + "'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "book_borrow");




            if (ds.Tables[0].Rows.Count != 0)
            {
                textBox9.Text = ds.Tables[0].Rows[0]["book_name"].ToString();
                textBox10.Text = ds.Tables[0].Rows[0]["book_author"].ToString();
                textBox11.Text = ds.Tables[0].Rows[0]["book_class"].ToString();
                textBox12.Text = ds.Tables[0].Rows[0]["book_press"].ToString();
                textBox13.Text = ds.Tables[0].Rows[0]["book_price"].ToString();
             


            }
            else
            {
                MessageBox.Show("没有找到被查询的书");
            }
            conn.Close();




        }


        private void button5_Click(object sender, EventArgs e)
        {
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            //UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
            String string_update = "update books  set book_name='"+textBox9.Text+"',book_author='"+textBox10.Text+"',book_class='"+textBox11.Text+"',book_press='"+textBox12.Text+"',book_price='"+textBox13.Text+"'where book_num='"+textBox8.Text+"'";
            SqlCommand cmd = new SqlCommand(string_update,conn);
            
            if (cmd.ExecuteNonQuery() > 0)
            {
                MessageBox.Show("修改成功");
            }
            conn.Close();






        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            this.timer1.Enabled = true;
            this.timer1.Start();
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            String string_select = "select count(*) from book_borrow where book_borrow='0'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select,conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "book_borrow_count");
            
            //DataTable tc = ds.Tables[0].Clone();
            //tc.TableName = "DataTable1";
            //ds.Tables.Add(tc);
            if (ds.Tables[0].Rows.Count != 0)
            {
                label15.Text = ds.Tables[0].Rows.Count.ToString();
            }
            else {
                label15.Text = "0";
            }
            conn.Close();
            //右边推荐
            String string_select_borrow = "select * from book_borrow  ORDER BY book_borrow_degree DESC ";
            da.SelectCommand = new SqlCommand(string_select_borrow, conn);
            da.Fill(ds, "book_borrow_degree");
            //DataTable td = ds.Tables[1].Clone();
            //td.TableName = "DataTable2";
            //ds.Tables.Add(td);
            if (ds.Tables[1].Rows.Count != 0)
             {
                 if (ds.Tables[1].Rows.Count==1)
                 {
                     label17.Text = ds.Tables[1].Rows[0]["book_borrow_name"].ToString();
                     label18.Text = "无";
                     label19.Text = "无";
                 }
                 else if (ds.Tables[1].Rows.Count ==2)
                 {
                     label17.Text = ds.Tables[1].Rows[0]["book_borrow_name"].ToString();
                     label18.Text = ds.Tables[1].Rows[1]["book_borrow_name"].ToString();
                     label19.Text = "无";
                 }
                 else if (ds.Tables[1].Rows.Count >=3)
                 {
                     label17.Text = ds.Tables[1].Rows[0]["book_borrow_name"].ToString();
                     label18.Text = ds.Tables[1].Rows[1]["book_borrow_name"].ToString();
                     label19.Text = ds.Tables[1].Rows[2]["book_borrow_name"].ToString();
                }
                 
             }
             else
             {
                 label17.Text = "无";
                 label18.Text = "无";
                 label19.Text = "无";
             }


            conn.Close();


            //下面详细
            this.timer1.Enabled = true;
            this.timer1.Interval = 100;
            this.timer1.Stop();
            String string_select_user_book = "select * from user_book ";
            da.SelectCommand = new SqlCommand(string_select_user_book, conn);
            da.Fill(ds, "book_user_book");
            if (ds.Tables[2].Rows.Count != 0)
            {
                foreach(DataRow rr in    ds.Tables[2].Rows  ){
                    foreach (DataColumn cc in rr.Table.Columns)
                    {
                        richTextBox1.Text += rr[cc].ToString();
                }
                    richTextBox1.Text += "\n";
                }
            }
            else
            {
                richTextBox1.Text = "无";
            }




        }


        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {


        }
    }
}
///form_user//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Timers;






  
 
   
  
  
  
















namespace library
{
    public partial class From_user : Form
    {
        public static String a ;


        public String Txt { 
        set{
                a=value; 
        }


            get{
                return a;
        }
        }
        public From_user()
        {
            InitializeComponent();
        }
        private void FormMain_Resize(object sender, EventArgs e) {


            this.tabPageRefresh() ;
        }
        private void tabPageRefresh()
        { 
        foreach(TabPage p in tabControl1.TabPages){
        p.Refresh();
        }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


        }


        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {


        }


        private void From_user_Load(object sender, EventArgs e)
        {
          






            // TODO: 这行代码将数据加载到表“mydataDataSet.books”中。您可以根据需要移动或删除它。
            this.booksTableAdapter.Fill(this.mydataDataSet.books);


        }


        private void panel4_Paint(object sender, PaintEventArgs e)
        {


        }


        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {


        }


        private void label2_Click(object sender, EventArgs e)
        {


        }


        private void label3_Click(object sender, EventArgs e)
        {


        }


        private void button1_Click(object sender, EventArgs e)
        {
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            String string_select = "select * from book_borrow where book_borrow_name='" + textBox1.Text + "'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "book_borrow");
            //  DataTable dt = new DataTable("newTable");
            // ds.Tables.Add(dt);


            if (ds.Tables[0].Rows.Count != 0)
            {
                DataRow row1 = ds.Tables[0].Rows[0];


                //此时的0 代表 已经借走, 1 表示没有借走
                if (row1["book_borrow"].ToString() == "1")
                {
                    label3.Text = "该书尚未借走";
                }
                else
                {
                    label3.Text = "该书已被借走";


                }
            }
            else
            {
                label3.Text = "没有找到被查询的书";
            }
            conn.Close();


        }


        private void button2_Click(object sender, EventArgs e)
        {
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();


            String string_select = "select * from book_borrow where book_borrow_name='" + textBox1.Text + "'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "book_borrow");


            String shuhao ;
             String startshijian ;
            if (ds.Tables[0].Rows.Count != 0)
            {
                DataRow row1 = ds.Tables[0].Rows[0];


                //此时的0 代表 已经借走, 1 表示没有借走
                if (row1["book_borrow"].ToString() == "1")
                {   shuhao=row1["book_borrow_num"].ToString() ;
                    label3.Text = "该书尚未借走";


                    String string_update = "update book_borrow set book_borrow=0 where book_borrow_name = '" + textBox1.Text + "'";
                    SqlCommand cmd = new SqlCommand(string_update, conn);
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        //MessageBox.Show("借阅成功");
                        startshijian = DateTime.Now.ToLongDateString().ToString();
                        String string_insert = "insert into user_book(user_name,user_num,book_name,book_num,borrow_time_start)values('"+a+"','"+label20.Text+"','"+textBox1.Text+"','"+shuhao+"','"+startshijian+"')";
                        SqlCommand cmd2 = new SqlCommand(string_insert, conn);
                         if (cmd2.ExecuteNonQuery() > 0)
                    {
                        MessageBox.Show("借阅成功");
                    }
                    }


                }
                else
                {
                    label3.Text = "该书已被借走";


                }
            }
            else
            {
                label3.Text = "没有找到被查询的书";
            }
            conn.Close();
        }


        private void button3_Click(object sender, EventArgs e)




        {
             String endshijian;
            //还书界面


            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();


            //首先搜索借书的表里面有没有借走
            String string_select = "select * from book_borrow where book_borrow_name='" + textBox2.Text + "'";
            SqlDataAdapter da_string_select = new SqlDataAdapter();
            da_string_select.SelectCommand= new SqlCommand(string_select, conn);
            DataSet ds_string_select = new DataSet();


            da_string_select.Fill(ds_string_select,"string_select");


            if (ds_string_select.Tables[0].Rows.Count != 0)
            {
                /1
                //label6.Text = "123";


                if (ds_string_select.Tables[0].Rows[0]["book_borrow"].ToString() == "0")
                {
                    /2
                    //label6.Text = "123";
                    //通过书号来找user_book里面的数据
                    String string_select_user_book = "select * from user_book where borrow_is='0' and book_num='" + ds_string_select.Tables[0].Rows[0]["book_borrow_num"].ToString() + "'";


                    da_string_select.SelectCommand = new SqlCommand(string_select_user_book, conn);
                    DataSet ds_string_select_user_book = new DataSet();
                    da_string_select.Fill(ds_string_select_user_book, "string_select_user_book");
                    if (ds_string_select_user_book.Tables[0].Rows.Count != 0)
                    {
                        /3
                        if (ds_string_select_user_book.Tables[0].Rows[0]["user_num"].ToString()==label20.Text)
                        {
                            /4
                            endshijian = DateTime.Now.ToLongDateString().ToString(); ;
                           // label6.Text = "查询1";
                            String string_update_user_book = "update user_book set borrow_is='1',borrow_time_end='" + endshijian + "' where user_num='" + label20.Text + "' ";
                            SqlCommand cmd = new SqlCommand(string_update_user_book, conn);
                            //if (ds_string_select_user_book.Tables[0].Rows[0]["user_num"].ToString()== " 123 ")
                            //{
                            if (cmd.ExecuteNonQuery() > 0)
                            {


                                String string_update_book_borrow = "update book_borrow set book_borrow='1' where book_borrow_num='" + ds_string_select.Tables[0].Rows[0]["book_borrow_num"].ToString() + "' ";
                                SqlCommand cmd_string_update_book_borrow = new SqlCommand(string_update_book_borrow, conn);
                                if (cmd_string_update_book_borrow.ExecuteNonQuery() > 0)
                                {
                                    label6.Text = "还书成功";


                                }
                                //}else{
                                //    label6.Text = "还书失败";
                                //}
                            }
                            else
                            {
                                label6.Text = "查询4";


                            }
                            //}else{
                            //    label6.Text = "还书失败" + ds_string_select_user_book.Tables[0].Rows[0]["user_num"].ToString();
                            //  }








                            /4


                        }
                        else
                        {
                            label6.Text = "还书失败";//+ ds_string_select_user_book.Tables[0].Rows[0]["user_num"].ToString();
                        }






                        /3
                    }else{
                        label6.Text = "错误查询";
                    }
                    //通过book_borrow的书号跟 user_book的书号作比较 如果一样且 borrow_is 为0 












                    //label6.Text = "还书成功";










                    /2
                }else if(ds_string_select.Tables[0].Rows[0]["book_borrow"].ToString() == "1") {
                    label6.Text = "该书未被借走";
                }
                /1
            }else{
             label6.Text = "没有找到被查询的书";
            }


        }


        private void label10_Click(object sender, EventArgs e)
        {


        }


        private void tabPage3_Click(object sender, EventArgs e)
        {


        }






        private void timer1_Tick_1(object sender, EventArgs e)
        {
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            
            String string_select = "select * from user_info where account='"+a+"'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "book_borrow");






            if (ds.Tables[0].Rows.Count != 0)
            {
                DataRow row1 = ds.Tables[0].Rows[0];
                label8.Text = row1["user_name"].ToString();
                 if (row1["user_sex"].ToString() == "0") {
                     label10.Text = "男";
                 }
                 else if (row1["user_sex"].ToString() == "1")
                 {
                     label10.Text = "女";
                }
                label12.Text = row1["user_age"].ToString();
                if (row1["user_rank"].ToString() == "0") {
                    label14.Text = "普通用户";
                } else if(row1["user_rank"].ToString() == "1"){
                label14.Text = "普通管理员";
                }
                else if (row1["user_rank"].ToString() == "2")
                {
                    label14.Text = "中级管理员";
                }
                else if (row1["user_rank"].ToString() == "3")
                {
                    label14.Text = "超级管理员";
                }
               
                label16.Text = row1["user_school"].ToString();
                label18.Text = row1["user_major"].ToString();
                label20.Text = row1["user_num"].ToString();
                label22.Text = row1["user_tel"].ToString();




            }
            conn.Close();
        }


  
    
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            //设置Timer控件可用
            this.timer2.Enabled = true;
            //设置时间间隔(毫秒为单位)
            //this.timer2.Interval = 1000;
            this.timer2.Start();


            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();


            String string_select = "select * from user_info where account='"+a+"'";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "book_borrow");




            if (ds.Tables[0].Rows.Count != 0)
            {




                DataRow row1 = ds.Tables[0].Rows[0];
                textBox3.Text = row1["user_name"].ToString();
                textBox4.Text = row1["user_id"].ToString();
                if (row1["user_sex"].ToString() == "0")
                {
                    checkBox1.Checked = true;
                }
                else if (row1["user_sex"].ToString() == "1")
                {
                    checkBox2.Checked = true;
                }


                textBox5.Text = row1["user_age"].ToString();
                textBox6.Text = row1["user_school"].ToString();
                textBox7.Text = row1["user_major"].ToString();
                textBox8.Text = row1["user_num"].ToString();
                textBox9.Text = row1["user_tel"].ToString();


            }
            conn.Close();
            this.timer2.Stop();
        }


        private void label31_Click(object sender, EventArgs e)
        {


        }


        private void button4_Click(object sender, EventArgs e)
        {


            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            String sex="0";
            if (checkBox1.Checked == true && checkBox2.Checked == true)
            {
                checkBox2.Checked = false;
                MessageBox.Show("不能都选");
            }else{
            if (checkBox1.Checked == true)
            {
                sex = "0";
            }
            else if (checkBox2.Checked == true)
            {
                 sex = "1";
            }}
            String string_update = "update user_info set  user_name='" + textBox3.Text + "',user_sex='" + sex + "', user_age='" + textBox5.Text + "', user_school='"+textBox5.Text+"', user_major='"+textBox7.Text+"', user_num='"+textBox8.Text+"', user_tel='"+textBox9.Text+"' where user_id='"+textBox4.Text+"'";
            SqlCommand cmd = new SqlCommand(string_update,conn);
            cmd.ExecuteNonQuery();
            MessageBox.Show("修改成功");
            conn.Close();


        }


        private void label34_Click(object sender, EventArgs e)
        {


        }


        private void button6_Click(object sender, EventArgs e)
        {
            this.Close();
            Form newMainform = new MainForm();
            newMainform.Show();
        }


        private void textBox8_TextChanged(object sender, EventArgs e)
        {


        }


        private void label8_Click(object sender, EventArgs e)
        {


        }


        private void label16_Click(object sender, EventArgs e)
        {


        }


        private void tabPage4_Click(object sender, EventArgs e)
        {


        }


        private void timer3_Tick(object sender, EventArgs e)
        {
            this.tabPage1.Refresh();
        }


        private void panel2_Paint(object sender, PaintEventArgs e)
        {


        }
    }
}
//form_user_create/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace library
{
    public partial class Form_user_create : Form
    {
        public Form_user_create()
        {
            InitializeComponent();
        }


  


        private void button1_Click(object sender, EventArgs e)
        {


            String xuehao="",account="";
            //注册页面
            String conn_string = "Data Source =.;Initial Catalog=mydata;User Id = sa;Password=huoying000615";
            SqlConnection conn = new SqlConnection(conn_string);
            conn.Open();
            String sex ="0";
          if (checkBox1.Checked == true && checkBox2.Checked == true)
            {
                checkBox2.Checked = false;
                MessageBox.Show("不能都选");
            }else{
            if (checkBox1.Checked == true)
            {
                sex = "0";
            }
            else if (checkBox2.Checked == true)
            {
                 sex = "1";
            }}


            //
            xuehao=textBox5.Text;
             String string_select = "select * from user_info where user_num='"+xuehao+"' ";
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(string_select, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "user_info_num");


            if (ds.Tables[0].Rows.Count != 0)
            {
                MessageBox.Show("学号已存在");
            }
            else {
                //MessageBox.Show("学号和账号错误");
                account=textBox7.Text;
                 String string_select2 = "select * from user_info where account='"+account+"' ";
            SqlDataAdapter daa = new SqlDataAdapter();
            daa.SelectCommand = new SqlCommand(string_select2, conn);
            DataSet dss = new DataSet();
            daa.Fill(dss, "user_info_account");


            if (dss.Tables[0].Rows.Count != 0)
            {
                MessageBox.Show("账号已存在");
            }
            else {


                String string_insert = "insert into user_info(user_name,user_sex,user_age,user_school,user_major,user_num,user_tel,account,password)values('" + textBox1.Text + "','" + sex + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "')";


                SqlCommand cmd = new SqlCommand(string_insert, conn);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("注册成功");
                    this.Close();
            }
            }














            /




         
            }
        }


        private void panel1_Paint(object sender, PaintEventArgs e)
        {


        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值