【发布时间】:2019-09-12 02:18:04
【问题描述】:
我试图将数据插入到我的本地主机数据库 (xampp phpmyadmin),但我一直收到此错误。我尝试查找异常,但未能找到任何答案。
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 ProductMaintenance
{
public partial class Form1 : Form
{
SqlConnection connection = new SqlConnection("server=localhost;user id=root123;database=test;allowuservariables=True;persistsecurityinfo=True");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
connection.Open();
SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into [mytable] (Name,Surname,Address) values (' "+ textBox1.Text + " ', '" + textBox2.Text + " ', ' " + textBox3 + "')";
cmd.ExecuteNonQuery();
connection.Close();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
【问题讨论】:
-
尝试将连接字符串更改为
server=localhost;user id=root123;database=test;Allow User Variables=True;persistsecurityinfo=True -
怎么是重复的?我的连接字符串有“允许用户变量 = True”
-
您使用的是哪个版本的 .net 框架???
标签: c#