惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
S
SegmentFault 最新的问题
量子位
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
博客园 - Franky
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
B
Blog RSS Feed
C
Check Point Blog
The Cloudflare Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
V
Visual Studio Blog
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - angelfeather

json中获取key值 iOS开发常用代码块(2) 区别不同浏览器,CSS hack写法 [推荐]13款js编辑器大全 web标准 CSS Sprites 用户控件(.ascx)与网页间(.aspx)如何传值的几种方法 彩色验证码 c#.net常用函数和方法集 ASP.NET中$#=的用法 - angelfeather - 博客园 利用MD5加密数据库中的密码 - angelfeather - 博客园 小记一篇~ - angelfeather - 博客园 推荐一个.net代码查看器Reflector 推荐一个学习asp.net的好地方 简单的ArrayList遍历 Microsoft .Net 框架 SDK 快速入门教程 asp.net简单的md5算法 遍历页面的所有button控件 GridView统计数据和修改Cell GridView格式化导出Excel GridView导出Excel
一段常用的Page_Load事件 (如果有更好的希望大家留言) - ange...
angelfeather · 2008-06-19 · via 博客园 - angelfeather

protected void Page_Load(object sender, EventArgs e)
  {
   SqlConnection myConnection = new SqlConnection("server=Localhost;database=pubs;uid=sa;pwd=;");//创建SQL连接
   SqlCommand myCommand = new SqlCommand("SELECT title, price FROM Titles WHERE price > 0", myConnection);//创建SQL命令
  
   try
   {
    myConnection.Open();//打开数据库连接
    MyGrid.DataSource = myCommand.ExecuteReader();//指定 DataGrid 的数据源
    MyGrid.DataBind();//绑定数据到 DataGrid
    myConnection.Close();//关闭数据连接
   }
   catch(Exception ex)
   {
    //捕获错误
    HttpContext.Current.Response.Write(ex.ToString());
   }
  } 

posted on 2008-06-19 14:46  angelfeather  阅读(444)  评论()    收藏  举报