using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
#region 网上找的东西
/*
SqlConnection conn = new SqlConnection(); //新建一个数据库连接对象
// conn = new SqlConnection();
conn.ConnectionString = "Data Source=CCSU1402-2;Initial Catalog=test;User ID=cgy123;Password=123123"; //设置连接信息
conn.Open(); //打开连接
string strsql = "select * from login"; //设置sql字符串代码
SqlCommand cmd = new SqlCommand(strsql, conn); //用command把连接信息和字符串组合在一起
SqlDataReader sqlreader = cmd.ExecuteReader(); //调用sqlcommand的ExecuteReader()方法来执行代码
while (sqlreader.Read()) //读出代码,
{
//lblInfo.Text+= sqlreader["name"].ToString();
ListBox1.Items.Add(sqlreader.GetString(0));
}
sqlreader.Close();
conn.Close();
* */
#endregion
protected void Button1_Click(object sender, EventArgs e)
{
#region 去年数据库的代码文件
//第一步: 设置连接信息
SqlConnection thisConn = new SqlConnection(@"Server=CCSU1402-2;Integrated Security=True;Database=test;User ID=cgy123;Password=123123");
//第二步:打开连接
thisConn.Open();
//第三步:提供者对象-命令对象,
SqlCommand thisCommand = thisConn.CreateCommand();
//具体命令
thisCommand.CommandText = "SELECT * FROM login";
//提供者对象:DataReader,用Command对象执行读操作,返回用户对象
SqlDataReader thisReader = thisCommand.ExecuteReader();
//用DataReader对象读取数据
while (thisReader.Read())
{
//DataReader提供索引符属性,允许把列引用按列名称的数组引用
//ListBox1.Items.Add(thisReader.GetString(0));
}
//关闭DataReader
thisReader.Close();
//关闭连接
thisConn.Close();
#endregion
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
#region 网上找的东西
/*
SqlConnection conn = new SqlConnection(); //新建一个数据库连接对象
// conn = new SqlConnection();
conn.ConnectionString = "Data Source=CCSU1402-2;Initial Catalog=test;User ID=cgy123;Password=123123"; //设置连接信息
conn.Open(); //打开连接
string strsql = "select * from login"; //设置sql字符串代码
SqlCommand cmd = new SqlCommand(strsql, conn); //用command把连接信息和字符串组合在一起
SqlDataReader sqlreader = cmd.ExecuteReader(); //调用sqlcommand的ExecuteReader()方法来执行代码
while (sqlreader.Read()) //读出代码,
{
//lblInfo.Text+= sqlreader["name"].ToString();
ListBox1.Items.Add(sqlreader.GetString(0));
}
sqlreader.Close();
conn.Close();
* */
#endregion
protected void Button1_Click(object sender, EventArgs e)
{
#region 去年数据库的代码文件
//第一步: 设置连接信息
SqlConnection thisConn = new SqlConnection(@"Server=CCSU1402-2;Integrated Security=True;Database=test;User ID=cgy123;Password=123123");
//第二步:打开连接
thisConn.Open();
//第三步:提供者对象-命令对象,
SqlCommand thisCommand = thisConn.CreateCommand();
//具体命令
thisCommand.CommandText = "SELECT * FROM login";
//提供者对象:DataReader,用Command对象执行读操作,返回用户对象
SqlDataReader thisReader = thisCommand.ExecuteReader();
//用DataReader对象读取数据
while (thisReader.Read())
{
//DataReader提供索引符属性,允许把列引用按列名称的数组引用
//ListBox1.Items.Add(thisReader.GetString(0));
}
//关闭DataReader
thisReader.Close();
//关闭连接
thisConn.Close();
#endregion
}
}