简体   繁体   中英

Inserting data to database from textbox using dataset

I have a page with a text box and a button where in I am trying to insert text into sqldatabase using database but its not working. I see nothing reflecting in database on button click and there's no error thrown. Please help

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


public partial class CM : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    SqlDataAdapter da;
    DataTable dt;
    SqlConnection con = new SqlConnection("server =consulting76\\SQLEXPRESS; database = msdb; Integrated Security=True");

    protected void Page_Load(object sender, EventArgs e)
    {
        da = new SqlDataAdapter("Select * from NOTESMAKER", con);
        da.Fill(ds, "NOTESMAKER");
        dt = ds.Tables["NOTESMAKER"];
    }

    protected void Button1_Click(object sender, EventArgs e)
    { 
        SqlCommand cmd = new SqlCommand("Insert into NOTESMAKER(NOTESMAKER) Values(@text1)", con);
        cmd.Parameters.Add(new SqlParameter("@text1", SqlDbType.NText)).Value = TextBox1.Text;
        da.InsertCommand = cmd;
        //cmd.ExecuteNonQuery();
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM