newscontent.aspx.cs

来自「B/S asp.net的C#编的网站」· CS 代码 · 共 50 行

CS
50
字号
using System;
using System.Data;
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;
using System.Data.SqlClient;

public partial class NewsContent : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string connstr = ConfigurationManager.AppSettings["constr"].ToString();
        SqlConnection conn = new SqlConnection(connstr);
        DataSet ds = new DataSet();

        try
        {
            string sql = "Select [Title],[Content] From [News] Where [NewsID] = '" + Request.QueryString["NewsID"] + "'";
            SqlCommand cmd = new SqlCommand(sql, conn);

            conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;            
            sda.Fill(ds);
        }
        catch (SqlException se)
        {
            se.ToString();
        }
        finally
        {
            conn.Close();
        }

        if (ds.Tables[0].Rows.Count > 0)
        {
            newsTitletxt.Text = ds.Tables[0].Rows[0][0].ToString();
            contenttxt.Text = ds.Tables[0].Rows[0][1].ToString();
        }
        

    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?