首页下载资源后端C#学习资料关于数据库连接

ZIPC#学习资料关于数据库连接

asalley1.28MB需要积分:1

资源文件列表:

C#.zip 大约有6个文件
  1. C#/
  2. C#/MySQL Connector NET 8.0.33.1.zip 552.6KB
  3. C#/usertable.sql 1.46KB
  4. C#/WinFormsAppMain.zip 776.42KB
  5. C#/断开式.txt
  6. C#/非断开.txt 1.71KB

资源介绍:

C#学习资料关于数据库连接
private void button1_Click(object sender, EventArgs e) { try { String user = textBoxUser.Text; String password = textBoxPassword.Text; String sex; String normal; StringBuilder sb = new StringBuilder(); if (radioButtonBoy.Checked) { sex = "男"; } else { sex = "女"; } if (checkBoxNET.Checked) { sb.Append(".NET "); } if (checkBoxC.Checked) { sb.Append("C "); } if (checkBoxJAVA.Checked) { sb.Append("JAVA "); } normal = sb.ToString(); string city = comboBox1.SelectedItem?.ToString() ?? ""; string love = listBox1.SelectedItem?.ToString() ?? ""; string mysqlcon = "server=localhost;database=usertable;user=root;password=123456"; string SQL = "INSERT INTO user (user, password, sex, city, normal, love) VALUES (@user, @password, @sex, @city, @normal, @love)"; using (MySqlConnection conn = new MySqlConnection(mysqlcon)) { conn.Open(); using (MySqlCommand MC = new MySqlCommand(SQL, conn)) { MC.Parameters.AddWithValue("@user", textBoxUser.Text); MC.Parameters.AddWithValue("@password", textBoxPassword.Text); MC.Parameters.AddWithValue("@sex", sex); MC.Parameters.AddWithValue("@city", city); MC.Parameters.AddWithValue("@normal", normal); MC.Parameters.AddWithValue("@love", love); MC.ExecuteNonQuery(); MessageBox.Show("添加注册成功"); } } Console.WriteLine("已关闭连接!"); } catch (MySqlException ex) { } }
100+评论
captcha