如何在C#中将SQL数据源手动绑定到GridView(ASP.Net) [英] How to do Manual Binding of SQL Data Source to GridView in C# (ASP.Net)

查看:101
本文介绍了如何在C#中将SQL数据源手动绑定到GridView(ASP.Net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GridView绑定ASP.Net(内置)中可用的SQL DataSource,但我无法完成任务请帮助我并逐步解决。

thankyou,

解决方案





试试这些 -



http://csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource- insert-edit.html [ ^ ]



http://www.aspdotnetfaq.com/Faq/How-to-insert-row-in-GridView-with-SqlDataSource.aspx [ ^ ]


 SqlConnection cn =  new  SqlConnection( 你的连接SCRING); 
SqlDataAdapter cmd = new SqlDataAdapter();
DataTable dt = new DataTable( TESTTABLE );
cmd.SelectCommand = new SqlCommand();
cmd.SelectCommand.Connection = cn;
cmd.SelectCommand.CommandText = 你的SELECT QUERY;
cmd.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();


  string  selectSQL =  选择查询; 
SqlConnection cnn = new SqlConnection(connectionString);
SqlDataAdapter adp = new SqlDataAdapter(selectSQL,cnn);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();


I am trying to bind SQL DataSource which is available in ASP.Net (inbuilt) with GridView but i cannot complete the task please help me and give step by step solution.
thankyou,

解决方案

Hi,

Try these-

http://csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource-insert-edit.html[^]

http://www.aspdotnetfaq.com/Faq/How-to-insert-row-in-GridView-with-SqlDataSource.aspx[^]


SqlConnection cn = new SqlConnection("YOUR CONNECTION SCRING");
SqlDataAdapter cmd = new SqlDataAdapter();
DataTable dt = new DataTable("TESTTABLE");
cmd.SelectCommand = new SqlCommand();
cmd.SelectCommand.Connection = cn;
cmd.SelectCommand.CommandText = "YOUR SELECT QUERY";
cmd.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();


string selectSQL = "select query";
           SqlConnection cnn = new SqlConnection(connectionString);
           SqlDataAdapter adp = new SqlDataAdapter(selectSQL, cnn);
           DataSet ds = new DataSet();
           adp.Fill(ds);
           GridView1.DataSource = ds;
           GridView1.DataBind();


这篇关于如何在C#中将SQL数据源手动绑定到GridView(ASP.Net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆