当前位置: 代码迷 >> ASP.NET >> 为何应用程序能访问数据库,而Aspx页面(相同代码)提示登录失败呢?多谢
  详细解决方案

为何应用程序能访问数据库,而Aspx页面(相同代码)提示登录失败呢?多谢

热度:9366   发布时间:2013-02-26 00:00:00.0
为何应用程序能访问数据库,而Aspx页面(相同代码)提示登录失败呢?谢谢
Aspx页面代码:
<%@   Page   Language= "C# "   %>
<%@   Import   NameSpace= "System "   %>
<%@   Import   NameSpace= "System.Data "   %>
<%@   Import   NameSpace= "System.Data.SqlClient "   %>
<Script   runat= "server ">
SqlConnection   con;
SqlCommand   cmd;
SqlDataAdapter   da;
DataSet   ds;
DataRow   dr;
SqlCommandBuilder   cmdbld;

void   Page_Load()
{
if(!IsPostBack)
LoadRequestData();
}
void   LoadRequestData()
{
lblDT.Text   =     System.DateTime.Now.Year.ToString()+ "年 "+System.DateTime.Now.Month.ToString()+ "月 "+System.DateTime.Now.Day.ToString()+ "日 ";
lblFN.Text   =   Request.Form[ "txtFN "];
lblLN.Text   =   Request.Form[ "txtLN "];
lblSex.Text   =   "radM ".Equals(Request.Form[ "Sex "])? "Male ": "Female ";
lblInterest.Text   =   Request.Form[ "ddlInterest "];
}
void   btnConfirm_Click(object   sender,   System.EventArgs   e)
{

String   strCon   =   "Data   Source   =   .\\SQLEXPRESS;   Initial   Catalog   =   HR;   Integrated   Security   =   SSPI;   Connect   Timeout   =   30; ";
con   =   new   SqlConnection(strCon);
cmd   =   new   SqlCommand();
cmd.Connection   =   con;
cmd.CommandType   =   CommandType.Text;
cmd.CommandText   =   "Select   *   From   NameList ";
da   =   new   SqlDataAdapter();
ds   =   new   DataSet();
da.SelectCommand   =   cmd;

con.Open();
da.Fill(ds, "NameList ");
con.Close();

dr   =   ds.Tables[ "NameList "].NewRow();
dr[ "FirstName "]   =   lblFN.Text;
dr[ "LastName "]   =   lblLN.Text;
dr[ "Sex "]   =   lblSex.Text;
dr[ "Interest "]   =   lblInterest.Text;
ds.Tables[ "NameList "].Rows.Add(dr);

con.Open();
da.Update(ds, "NameList ");
con.Close();

//cmdbld   =   new   SqlCommandBuilder(da);
//da.UpdateCommand   =   cmdbld.GetUpdateCommand();
//da.InsertCommand   =   cmdbld.GetInsertCommand();
//da.DeleteCommand   =   cmdbld.GetDeleteCommand();


}
</Script>

<html>
<head>
<title>   Verification   Form   </title>
</head>
<body>
<h1   align= "center "> Verification   Form   </h1>
<form   runat= "server ">
<table   align= "center "   border=1   width=500>
<tr>
<td   width=200> Today 's   Date </td>
<td> <asp:Label   runat= "server "   id= "lblDT "   /> </td>
</tr>
<tr>
<td> First   Name: </td>
<td> <asp:Label   runat= "server "   id= "lblFN "   width= "100% "   /> </td>
</tr>
  相关解决方案