测试链接并显示查询数据
代码说明:
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;//Download by http://down.liehuo.netusing System.Data.SqlClient;namespace Case05_12{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { //生成连接数据库字符串 string ConStr = "data source=.;database=ljp;uid=sa;pwd=123"; //定义SqlConnection对象实例 SqlConnection con = new SqlConnection(ConStr); //定义Select查询语句 string Sql = "select*from biaoge"; SqlDataAdapter ada = new SqlDataAdapter(Sql, con); DataSet ds = new DataSet(); //定义DataSet对象实例 ada.Fill(ds); //连接数据表格,显示数据 this.dataGridView1.DataSource = ds.Tables[0].DefaultView; } catch { return; } } private void button2_Click(object sender, EventArgs e) { this.Close(); Application.Exit(); } }}
下载说明:请别用迅雷下载,失败请重下,重下不扣分!