ado:SqlDataAdapter,dataset 与SqlDataReader的用法一
Posted 杰的记事本——javascript.shop
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ado:SqlDataAdapter,dataset 与SqlDataReader的用法一相关的知识,希望对你有一定的参考价值。
原文发布时间为:2008-08-01 —— 来源于本人的百度文章 [由搬家工具导入]
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.htmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection pubsConn = new SqlConnection("Server=.\\SQLEXPRESS;Database=pubs;Integrated Security=true");
//SqlConnection pubsConn = new SqlConnection(ConfigurationManager.ConnectionStrings["pubsConn"].ConnectionString);
//pubsConn.Open();
SqlDataAdapter sda = new SqlDataAdapter("SELECT TOP(10) * FROM authors", pubsConn);
DataSet ds = new DataSet();
sda.Fill(ds, "pubauthor");
GridView1.DataSource = ds.Tables["pubauthor"];
GridView1.DataBind();
foreach (DataRow dr in ds.Tables["pubauthor"].Rows)//从dataset表中获取某一列的所有值
{
ListBox1.Items.Add(dr["au_lname"].ToString());
}
pubsConn.Close();
SqlCommand sqlcmd=new SqlCommand("SELECT * FROM authors",pubsConn);
pubsConn.Open();
SqlDataReader sdr=sqlcmd.ExecuteReader();
if(sdr.HasRows)
{
while(sdr.Read())
{
DropDownList1.Items.Add(sdr["au_lname"].ToString());
//DropDownList1.Items.Add(sdr[1].ToString());
//ListItem item = new ListItem(sdr.GetString(1), sdr.GetString(1));
//DropDownList1.Items.Add(item);
}
}
sdr.Close();
pubsConn.Close();
}
}
以上是关于ado:SqlDataAdapter,dataset 与SqlDataReader的用法一的主要内容,如果未能解决你的问题,请参考以下文章
java.lang.NoClassDefFoundError: org/springframework/util/unit/DataSize
java.lang.NoClassDefFoundError: org/springframework/util/unit/DataSize