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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
char[] name;
int age;
name = textBox1.Text.ToCharArray();
age = System.Int32.Parse(textBox2.Text);
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=192.168.1.60;database=Test;uid=sa;pwd=123abc!";
con.Open();
/*
SqlDataAdapter 对象。 用于填充DataSet (数据集)。
SqlDataReader 对象。 从数据库中读取流..
后面要做增删改查还需要用到 DataSet 对象。
*/
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "INSERT INTO [Test].[dbo].[stu]([name],[age])VALUES('李',"+age+")";
SqlDataReader dr = com.ExecuteReader();//执行SQL语
dr.Close();//关闭执行
con.Close();//关闭数据库
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
char[] name;
int age;
name = textBox1.Text.ToCharArray();
age = System.Int32.Parse(textBox2.Text);
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=192.168.1.60;database=Test;uid=sa;pwd=123abc!";
con.Open();
/*
SqlDataAdapter 对象。 用于填充DataSet (数据集)。
SqlDataReader 对象。 从数据库中读取流..
后面要做增删改查还需要用到 DataSet 对象。
*/
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "INSERT INTO [Test].[dbo].[stu]([name],[age])VALUES('李',"+age+")";
SqlDataReader dr = com.ExecuteReader();//执行SQL语
dr.Close();//关闭执行
con.Close();//关闭数据库
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}