---------------------- Windows Phone 7手机开发、.Net培训、期待与您交流! --------------------
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 ADO.NET
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnConnetion_Click(object sender, EventArgs e)
{
string strcon = @"Data Source=localhost;Initial Catalog=student;Integrated Security=True;";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
string sqlStrSelect = "select * from T1";
try
{
SqlDataAdapter adapter = new SqlDataAdapter(sqlStrSelect, conn);
DataSet dstable = new DataSet();
adapter.Fill(dstable, "testTable");
dataGridView1.DataSource = dstable.Tables["testTable"];
dataGridView1.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
------------------------ Windows Phone 7手机开发、.Net培训、期待与您交流! ----------------------
详细请查看:http://net.itheima.com/