我写的代码总是显示无法加载,我用VS创建新页的时候提示我 未能加载类型“temp.Global”。
等我把这个文件删了就提示我inherits=" **** "这里的命名空间无法加载,我要是用DM直接编辑的话就直接提示我inherits=" **** " 无法加载,我弄了好几天,也没弄明白,希望大虾们指点一二。。。。
以下是代码:test.aspx
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false" Inherits="testDataAdapter.DataAdapterApplication" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox runat="server" ID="TextBox1" />
<asp:Button runat="server" ID="Button1" />
<asp:Table runat="server" ID="Table1">
</asp:Table>
</form>
</body>
</html>
以下为test.aspx.cs 变色部分为我所写,其余是自动生成
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;
namespace testDataAdapter
{
/// <summary>
/// test 的摘要说明。
/// </summary>
public class DataAdapterApplication : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Table Table1;
private void Page_Load(object sender, System.EventArgs e)
{
Text1.Text="";
}
public void Button1_Click(object sender,System.EventArgs e)
{
SqlConnection myConnection=new SqlConnection();
myConnection.ConnectionString="server=local;database=data;user id=sa;pwd=sa";
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=myConnection;
long strID=long.Parse(Text1.Text);
myCommand.CommandText="select * from admin where id="+strID;
DataSet ds=new DataSet();
SqlDataAdapter myAdapter=new SqlDataAdapter();
myAdapter.SelectCommand=myCommand();
myAdapter.Fill(ds,"admin");
TableRow trHead=new TableRow();
TableCell tcHead1=new TableCell();
TableCell tcHead2=new TableCell();
tcHead1.Text="用户名";
tcHead2.Text="密码";
trHead.Cells.Add(tcHead1);
trHead.Cells.Add(tcHead2);
Table1.Rows.Add(trHead);
TableRow trContent=new TableRow();
TableCell tcContent1=new TableCell();
TableCell tcContent2=new TableCell();
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
tcContent1.Text=ds.Tables[0].Rows[i][0];
tcContent2.Text=ds.Tables[0].Rows[i][1];
}
trContent.Cells.Add(tcContent1);
trContent.Cells.Add(tcContent2);
Table1.Rows.Add(trContent);
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}