note.aspx.cs

来自「前台首页:users/index.aspx 后台首页:login.aspx 」· CS 代码 · 共 73 行

CS
73
字号
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 users_note : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bind();
        }
    }
    void bind()
    {
        SqlConnection con = new SqlConnection("Data source=localhost;uid=sa;pwd=;database=Ebusiness");
        con.Open();
        SqlCommand comm = new SqlCommand("select askid, asktitle ,asktime from service_ask", con);
        DataSet ds = new DataSet();
        SqlDataAdapter sqld = new SqlDataAdapter();
        sqld.SelectCommand = comm;
        sqld.Fill(ds,"tab");
        GridView1.DataSource =ds.Tables["tab"].DefaultView;
        GridView1.DataBind();
        con.Close();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {

        string str = Session["user"].ToString();
        if (str == "")
        {
            ShowMassage("你还没有登陆,不能发表话题");
        }
        else
        {
            SqlConnection con = new SqlConnection("Data source=localhost;uid=sa;pwd=;database=Ebusiness");
            con.Open();
            SqlCommand comm = new SqlCommand("insert into service_ask(asktitle,askcontent,askuser,asktime) values(@asktitle,@askcontent,@askuser,@asktime)", con);
            comm.Parameters.Add("@asktitle", SqlDbType.VarChar, 50).Value = TextBox1.Text;
            comm.Parameters.Add("@askcontent", SqlDbType.VarChar, 8000).Value = TextBox2.Text;
            comm.Parameters.Add("@askuser", SqlDbType.VarChar, 50).Value = str;
            comm.Parameters.Add("@asktime", SqlDbType.DateTime).Value = DateTime.Now.ToString();

            comm.ExecuteNonQuery();
            con.Close();
            ShowMassage("发表成功");
            TextBox1.Text = "";
            TextBox2.Text = "";
        }
        bind();

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
    }
    public void ShowMassage(string msg)
    {
        Response.Write("<script>window.alert('" + msg + "')</script>");
    }
}

⌨️ 快捷键说明

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