C#中操纵SqlServer数据库
来源:互联网 发布:js字符串长度格式化 编辑:程序博客网 时间:2024/05/16 05:22
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)
{
}
}
}
0 0
- C#中操纵SqlServer数据库
- 在C#中操纵Oracle数据库
- c# 数据库操纵封装
- c#中sqlserver数据库事务处理
- C#语言操纵数据库事务
- C#操纵数据库简单记录
- C# 在SQLSERVER数据库中存取图片
- C# 在SQLSERVER数据库中存取图片
- C# 在SQLServer中附加一个数据库
- c#中操纵XML文件
- c#中操纵XML文件
- android中操纵sqlite数据库
- JDBC操纵数据库的步骤(以SQLServer为例)
- C#操作SQLServer数据库
- C#连接sqlserver数据库
- c#连接sqlserver数据库
- c#连接sqlserver数据库
- C#操作SqlServer数据库
- 201604-1-折点计算
- Html页面中的资源路径详解
- 启用了不安全的HTTP方法
- Jquery横向伸缩
- 如何方便快速在指定文件夹打开命令行
- C#中操纵SqlServer数据库
- Fragment调用PopupWindow工具封装类开启拍照或相册选择图片后无法回调的解决办法!
- CodeForces 723A-The New Year: Meeting Friends(很水)
- 工作总结25 Eclipse里Serve Modules without publishing导致项目加载不成功的主凶
- Jquery网站导航的 普通下拉菜单
- 第五届蓝桥杯软件类省赛真题-C-C-2_等额本金
- Bootstrap3 表单-被支持的控件:输入框
- study-10 linux系统网络基础知识及配置
- [BZOJ]1036: [ZJOI2008]树的统计Count