asp.net 调用数据库方法

news/2024/7/7 12:45:33

使用前置代码调用数据库

我使用windows身份验证登录sqlserver

在前置代码中添加

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db_StudentConnectionString %>"
                        SelectCommand="SELECT * FROM [tb_StuInfo]"></asp:SqlDataSource>

在web.config 中添加

<connectionStrings>
    <add name="db_StudentConnectionString" connectionString="Data Source=WUHONGXING-PC;Initial Catalog=mydatabase;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>


使用后置代码调用数据库

后置代码中添加

string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);

在web.config 中添加

<appSettings>
  <add key="ConnectionString" value="Server=WUHONGXING-PC;Database=mydatabase;Integrated Security=true;"></add>
</appSettings>



http://www.niftyadmin.cn/n/4002355.html

相关文章

linux下修改ext3硬盘为nst,重装系统之旅之二

为了开发&#xff0c;又需要安装linux系统了&#xff0c;在笔记本电脑上已经有一个win7 的系统&#xff0c;于是download了一个fedora 19 dvd版本的iso&#xff0c;又开始安装了。在win7 下面只是在开机的时候将grub4dos添加进boot 菜单就废了不少的事情(没用本文的添加方式,使…

Hadoopif.for.while 语句

if 语句 echo 当前参数个数:$# if [ $# -lt 3 ];then echo 参数小于3;elif [ $# -gt 5 ];then echo 参数大于5;fi; To have broken heart means you have tired for something for 语句 for (( x1 ; x<100 ; xx1 )); do echo x:$x ; done ; 输出1~100 for (( x1 ; x<7 ;…

asp.net登录控件出错

“/”应用程序中的服务器错误。 WebForms UnobtrusiveValidationMode 需要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptResourceMapping。 解决办法&#xff1a; 删除web.config 配置文件中 的<httpRuntime targetFramework"4.5&q…

linux多线程编写哲学家,linux基础实验报告含代码剖析.doc

Linux基础实验目录实验一3实验二4实验三6实验四9实验五11实验六14实验七16实验一 螺旋矩阵实验目的熟悉linux下c程序编写。掌握Makefile编写方法。实验环境和工具Red Hat Linux实验流程编写螺旋矩阵程序编写Makefile文件实验结果实验心得通过这次实验&#xff0c;我熟悉了linux…

asp.net 使用登录控件

新建数据库membershiptest 打开C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql.exe 新建项目 创建web窗体 default&#xff0c;account&#xff0c;login&#xff0c;passwordreset&#xff0c;register 配置web.config <?xml version"1.0"?&…

fetch 如何请求数据

一 序言 在 传统Ajax 时代&#xff0c;进行 API 等网络请求都是通过XMLHttpRequest或者封装后的框架进行网络请求,然而配置和调用方式非常混乱&#xff0c;对于刚入门的新手并不友好。今天我们介绍的Fetch提供了一个更好的替代方法&#xff0c;它不仅提供了一种简单&#xff0c…

linux getopts用法,shell中getopt/getopts的使用 getarg和getind意义

getopts配合case来进行操作时有两个隐含变量&#xff1a;一个是OPTARG&#xff0c;用来取当前选项的值&#xff0c;另外一个是OPTIND&#xff0c;代表当前选项在参数列表中的位移。OPTIND是一个特殊的变量&#xff0c;它的初始值是1&#xff0c;每次getopts处理完一个命令参数后…

asp.net 母板

母板 占位 ....内容 <asp:ContentPlaceHolder id"ContentPlaceHolder1" runat"server"> </asp:ContentPlaceHolder> ....内容 子页 <asp:Content ID"Content2" ContentPlaceHolderID"ContentPlaceHolder2" Runat&q…