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 測(cè)試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())//創(chuàng)建連接對(duì)象{conn.ConnectionString = ConnectionString;//給連接對(duì)象的連接路徑賦值conn.Open();//運(yùn)行連接對(duì)象,即是連接數(shù)據(jù)庫SqlCommand cmd = new SqlCommand();//創(chuàng)建命令對(duì)象cmd.Connection = conn;//命令對(duì)象通過連接對(duì)象連接數(shù)據(jù)庫發(fā)送命令cmd.CommandText = "insert into 病人 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";//命令對(duì)象發(fā)送命令的原文本int i = cmd.ExecuteNonQuery();//運(yùn)行命令對(duì)象MessageBox.Show("插入成功!");}}private void textBox1_TextChanged(object sender, EventArgs e){}}}
如下代碼運(yùn)行后,顯示問題出錯(cuò)```不支持關(guān)鍵字:?為什么呢?
侃侃無極
2022-04-08 17:07:54