从Form中textBox中读取数据存入数据库
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 addStaffInfo{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } PRivate void label2_Click(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void textBox5_TextChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void button1_Click(object sender, EventArgs e) { string str= "Data Source = YANG*****; Initial Catalog = appDB; Integrated Security = True"; SqlConnection myConn =new SqlConnection(str); myConn.Open(); string sqlStr=" insert into Table_1(姓名,电话,银行卡卡号,开户地址,备注) values('"+textBox1.Text.ToString()+"','"+textBox2.Text.ToString()+ "','" + textBox3.Text.ToString() + "','" + textBox4.Text.ToString() + "','" + textBox5.Text.ToString() + "') "; SqlCommand myCmd = new SqlCommand(sqlStr, myConn); int i= myCmd.ExecuteNonQuery();//受影响的行数 MessageBox.Show(i.ToString()); myConn.Close(); } private void textBox6_TextChanged(object sender, EventArgs e) { } private void textBox7_TextChanged(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } }}新闻热点
疑难解答