日期:2014-05-18  浏览次数:20804 次

如何把SQL数据传到内存DATATABLE???急用
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
string strSqlconn = "server = (local); database = baomingonline; uid = sa ; pwd = ok";
string strsql = "select stuname,shenfenzheng,huji,scool,xueli,email from stuinfo where stuname="+Session["stuname"]+"";
SqlConnection conn = new SqlConnection(strSqlconn);
DataTable DT = 
---------------------------//这行我该怎样写才能把我查询到的数据传入datatable中?????????并在我的repater控件中显示。

   
try
{  
conn.Open();
Repeater1.DataSource=DT;
Repeater1.DataBind();
}
finally
{
conn.Close();
}

}
}


我是用的repater绑的,html代码已经绑定了。
第一次发贴,刚学这个.net.好难弄,各位大虾多帮助一下哈,

------解决方案--------------------
C# code

SqlDataAdapter sda=new SqlDataAdapter(strsql,conn);
DataTable DT=new DataTable();
sda.Fill(DT);

------解决方案--------------------
string strSqlconn = "server = (local); database = baomingonline; uid = sa ; pwd = ok"; 
string strsql = "select stuname,shenfenzheng,huji,scool,xueli,email from stuinfo where stuname="+Session["stuname"]+""; 
SqlConnection conn = new SqlConnection(strSqlconn); 

try
{
conn.Open();
DataAdapter da=new DataAdapter(strsql,conn);
DataTable DT=new DataTable();
da.Fill(dt);
Repeater1.DataSource=DT; 
Repeater1.DataBind(); 



}
...