本文介绍了工作但不会保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Project1
{
public partial class Register : Form
{
private MySqlConnection myCon = new MySqlConnection("server=MKHX112208;uid=ojt;pwd=Password1;database=ask_it");
private MySqlCommand myCom;
public Register()
{
InitializeComponent();
}
MySqlConnection con;
MySqlCommand cmd;
MySqlDataReader dr;
private void btnRegister_Click(object sender, EventArgs e)
{
con.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
{
cmd.CommandText = "INSERT INTO users (firstname, lastname, username, password, emailadd) VALUES(@firstname, @lastname, @username, @password, @emailadd)";
cmd.Parameters.AddWithValue("@firstname", txtFirstName.Text);
cmd.Parameters.AddWithValue("@lastname", txtLastName.Text);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
cmd.Parameters.AddWithValue("@emailadd", txtEmailadd.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Saving is done!");
}
}
推荐答案
这篇关于工作但不会保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!