为了账号安全,请及时绑定邮箱和手机立即绑定

如下代码运行后,显示问题出错```不支持关键字:?为什么呢?

如下代码运行后,显示问题出错```不支持关键字:?为什么呢?

侃侃无极 2022-04-08 17:07:54
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 测试2{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){//Data Source=L_RYAN-PC\SQLEXPRESS;Initial Catalog=test;Integrated Security=Truestring ConnectionString = "SIMON-PC\\SQLEXPRESS\\SQLEXPRESS;Initial Catalog=Hospetal;Integrated Security=True";using(SqlConnection conn = new SqlConnection())//创建连接对象{conn.ConnectionString = ConnectionString;//给连接对象的连接路径赋值conn.Open();//运行连接对象,即是连接数据库SqlCommand cmd = new SqlCommand();//创建命令对象cmd.Connection = conn;//命令对象通过连接对象连接数据库发送命令cmd.CommandText = "insert into 病人 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";//命令对象发送命令的原文本int i = cmd.ExecuteNonQuery();//运行命令对象MessageBox.Show("插入成功!");}}private void textBox1_TextChanged(object sender, EventArgs e){}}}
查看完整描述

1 回答

?
沧海一幻觉

TA贡献1824条经验 获得超5个赞

string ConnectionString = "server=SIMON-PC\\SQLEXPRESS\\SQLEXPRESS;Initial Catalog=Hospetal;Integrated Security=True";

查看完整回答
反对 回复 2022-04-11
  • 1 回答
  • 0 关注
  • 192 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信