c#vs连接SQL sever数据库入门操作

对于需要连接数据库的项目,可以参考的简单初级代码。实现打开数据库,读入数据功能

 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 SQL_sever
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string Eid = txtID.Text;
string PName = txtPro.Text;
string EOut = Money.Text;
SqlConnection Sql = new SqlConnection();
Sql.ConnectionString = "server=.;database=风投数据;uid=sa;pwd=123";//根据本机地址,以超级管理员身份进入
Sql.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = Sql;
cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into Project values('"+Eid+"',"+PName+","+EOut+")";
SqlDataReader dr = cmd.ExecuteReader();//执行SQL语句
dr.Close();//关闭执行
Sql.Close();//关闭数据库
}
}
}
上一篇:[转载]SharePoint 2013测试环境安装配置指南


下一篇:QT开发环境安装配置教程