加入收藏 | 设为首页 | 会员中心 | 我要投稿 海洋资讯信息网_我爱站长网 (https://www.haijunwang.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

ASP.NET数据库连接实例-ASP教程,数据库相关

发布时间:2022-10-21 15:17:57 所属栏目:Asp教程 来源:
导读:  using system;

  using system.collections;

  using system.componentmodel;

  using system.data;

  using system.drawing;

  using system.web;

  using system.web.ses
  using system;
 
  using system.collections;
 
  using system.componentmodel;
 
  using system.data;
 
  using system.drawing;
 
  using system.web;
 
  using system.web.sessionstate;
 
  using system.web.ui;
 
  using system.web.ui.webcontrols;
 
  using system.web.ui.htmlcontrols;
 
  using system.data.sqlclient;
 
  namespace example01
 
  {
 
  ///
 
  /// webform1 的摘要说明。
 
  ///
 
  public class webform1 : system.web.ui.page
 
  {
 
  private void page_load(object sender, system.eventargs e)
 
  {
 
  // 在此处放置用户代码以初始化页面
 
  response.write("
 
  第一个连接数据库的实例
 
  ");
 
  sqlconnection myconnection = new sqlconnection("server=localhost;uid=sa;pwd=sa");
 
  try
 
  {
 
  myconnection.open();//打开数据库链接
 
  response.write("链接成功!");
 
  }
 
  catch
 
  {
 
  response.write("链接失败!");
 
  }
 
  }
 
  #region web 窗体设计器生成的代码
 
  override protected void oninit(eventargs e)
 
  {
 
  //
 
  // codegen: 该调用是 asp.net web 窗体设计器所必需的。
 
  //
 
  initializecomponent();
 
  base.oninit(e);
 
  }
 
  ///
 
  /// 设计器支持所需的方法 – 不要使用代码编辑器修改
 
  /// 此方法的内容。
 
  ///
 
  private void initializecomponent()
 
  {
 
  this.load += new system.eventhandler(this.page_load);
 
  }
 
  #endregion
 
  }
 
  }
 

(编辑:海洋资讯信息网_我爱站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章