ASP.NET学习

第一、注意版本问题
第二、IIS 5.1 .net的整合
应该先装IIS,再装VS。因为.NET 2.0要修改IIS中的设置

不过如果你先装了VS也不要紧,到你的C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727中找,有个工具叫 aspnet_regiis.exe

运行方法如下:
1.开始-->运行-->输入cmd,运行
2.DOS窗口打开以后,在DOS窗口内进入上面的文件夹
3.输入 aspnet_regiis.exe -i -enable
参考资料
lunzi   2009-01-02 20:16:04 阅读:392  评论:1  引用:0
http://www.red-gate.com/products/reflector/
lunzi   2008-10-13 13:39:44 阅读:1275  评论:0  引用:0
资料
lunzi   2008-10-05 23:29:26 阅读:193  评论:0  引用:0

学习ASP.NET的一点感受,我学习的是基于C#的部分,感觉C#特别
像java,所以进行简单开发看一天就可以了,前台视图和C# 的结
合我感觉更像java的Tapestry框架,也是基于事件驱动的开发模
式,因为用过Tapestry所以现在学习起ASP.NET感觉难度不大,
也许还没有进入深入开发的原因吧!以下是我用ASP.NET开发
的一个的留言板,主要是测试用的,因此非常简单。这次目标
主要是把ASP.NET的一个系统,用java重写,现在已经实现,
因此也不计划太深入的继续往下学习这个了

第一、添加留言的页面Defalt.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns=
"http://www.w3.org/1999/xhtml" >
<head runat=
"server">
    <title>无标题页</title>
</head>
<body>
    <form id=
"form1" runat="server">
    <div>
        userName:<asp:TextBox ID=
"guest_Msg" runat="server" TextMode="MultiLine"></asp:TextBox><br />
        <asp:Button ID=
"send_Message" runat="server" Text="发表留言" OnClick="send_Message_Click"/></div>
    </form>
</body>
</html>
对应的后台处理代码Default.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
//加入的命名空间
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    public const string connString =
"Data Source=IP;Initial Catalog=数据库;User ID=用户名;Password=密码";

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void send_Message_Click(object sender, EventArgs e)
    {
        string msg = guest_Msg.Text;
        if(msg!=null&&!
"".Equals(msg)){
            addMsg(msg);
            Response.Redirect(
"Default.aspx");
        }
        
    }
    private void addMsg(string msg)
    {
        string Sql =
"INSERT INTO guestbook(ID,UserName)values(newid(),'"+msg+"')";

        SqlConnection conn = new SqlConnection(connString);
        SqlCommand cmd = new SqlCommand(Sql, conn);
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
    }
}
第二、显示留言列表的页面ShowMsg.aspx
<%@ Page Language=
"C#" AutoEventWireup="true" CodeFile="ShowMsg.aspx.cs" Inherits="ShowMsg" %>

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns=
"http://www.w3.org/1999/xhtml" >
<head runat=
"server">
    <title>无标题页</title>
</head>
<body>
    <form id=
"form1" runat="server">
    <div>
        <asp:Repeater ID=
"rpt_Message" runat="server">
        <ItemTemplate>
         <table>
           <tr>
             <td>留言ID</td>
             <td>留言内容</td>
           </tr>
           <tr>
             <td><%# Eval(
"ID")%></td>
             <td><%# Eval(
"UserName")%></td>
           </tr>
         </table>
        </ItemTemplate>
        </asp:Repeater>
        
    </div>
    </form>
</body>
</html>
与之对应的后台代码ShowMsg.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ShowMsg : System.Web.UI.Page
{
    public const string connString =
"Data Source=IP;Initial Catalog=数据库;User ID=用户名;Password=密码";

    protected void Page_Load(object sender, EventArgs e)
    {
        SetBind();
    }

    private void SetBind()
    {
        using (SqlConnection conn = new SqlConnection(connString))
        {
            string cmdText =
"SELECT * FROM guestbook";
            SqlDataAdapter da = new SqlDataAdapter(cmdText,conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataTable dt = ds.Tables[0];
            rpt_Message.DataSource = dt;
            rpt_Message.DataBind();
        }
    }

}


lunzi   2007-12-13 16:34:27 阅读:492  评论:1  引用:0

由于工作需要,计划拿出一个星期的时间学习一下ASP.NET。
C#初步给我的感觉,非常像java,但是写总感觉没有灵巧,也许是不太习惯的原因。先熟悉一下 再说。。。
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.IO;

namespace TestCNo
{
    class Program
    {
        public const string connString =
"Data Source=IP;Initial Catalog=数据库名称;User ID=用户名 ;Password=密码";

        static void Main(string[] args)
        {
            p(
"d");
            Program m = new Program();
            m.TestDataReader();
            
//m.TestDataInsert();
          
        }

        public void TestDataInsert()
        {
            string Sql =
"INSERT INTO guestbook(ID,UserName)values(newid(),'lunzi')";

            SqlConnection conn = new SqlConnection(connString);
            SqlCommand cmd = new SqlCommand(Sql,conn);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

        }
        public void TestDataReader()
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                string cmdText =
"SELECT * FROM guestbook";
                SqlCommand cmd = new SqlCommand(cmdText, conn);
                cmd.Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                
// Not the best way to obtain data binding ...
                Log log;
                while (reader.Read())
                {
                    
//int count = reader.FieldCount;
                    log = new Log();
                    log.setUserId(reader.GetString(1));
                    p(log.getUserId());
                    p(
"\n-------------------------");
                }
                reader.Close();
                cmd.Connection.Close();
            }
        }

        static void p(string s)
        {
            Console.WriteLine(s);
        }
    }

    class Log
    {
        private string userId;

        public void setUserId(string userid)
        {
            userId = userid;
        }

        public string getUserId()
        {
            return userId;
        }
    }
}

lunzi   2007-12-09 17:29:49 阅读:640  评论:0  引用:0
Copyright@2004-2010 powered by YuLog