Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#中创建注册表?_C#_Mysql - Fatal编程技术网

如何在C#中创建注册表?

如何在C#中创建注册表?,c#,mysql,C#,Mysql,USN-主键 密码和联系电话-浮动 其余的是瓦查尔 如何防止我的代码出错 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

USN-主键 密码和联系电话-浮动 其余的是瓦查尔 如何防止我的代码出错

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Portal_Exam1
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=ADMIN-\MSSQLSERVERR;Initial Catalog=Register;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("insert into Student values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')", con);
            con.Open();
            int i = cmd.ExecuteNonQuery();


     con.Close();
        if (i > 0)
        {
            MessageBox.Show("Data inserted successfully!");
        }
        else
        {
            MessageBox.Show("There is some problem");
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Hide();
        Admin_Panel aa = new Admin_Panel();
        aa.Show();
    }

    private void button3_Click(object sender, EventArgs e)
    {
        textBox1.Text = "";
        textBox2.Text = "";
        textBox3.Text = "";
        textBox4.Text = "";
        textBox5.Text = "";
        textBox6.Text = "";
        textBox7.Text = "";
    }
}
}


在查询中插入列名

"Sqlcommand cmd = New Sqlcommand("INSERT INTO tablename (column_name) VALUES ('" + textbox1.text + "')",con);
另外,如果使用参数化查询也会更好

"Sqlcommand cmd = New Sqlcommand("INSERT INTO tablename (column_name) VALUES (@text_box)",con);
cmd.Parameters.AddWithValue("@text_box", textBox1.text);

如何防止什么样的错误?你的代码很容易受到sql注入攻击。潜在的sql注入请考虑更正它…每次我在我的表单上注册一个帐户时,它都会说这是我学校的项目。。如果我的错误已经解决了,我会尽快解决的injection@RonBeyer观看我上传的视频