Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
the Problem is my code is Not insert/Saving New Record Into My sql database using asp.net c# and gives me no error!

here is my code :
C#
public partial class AddNews_AddNews : System.Web.UI.Page
    {
        protected SqlConnection _connection;
        protected SqlCommand _command;
        protected SqlDataAdapter _adp;
        protected System.Data.DataTable _tbl;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            prepareConnection();
            _command.CommandText = "INSERT INTO" + drbdlSection.SelectedItem + "(Title,Contect) VALUES (" + titleTextBox.Text + "," + CKEditor1.Text + ");";
        }

        protected void prepareConnection()
        {
            _connection = new SqlConnection(@"Data Source=localhost;Initial Catalog=BrainStorms;User ID=sa;Password=ameer123");
            _connection.Open();
            _command = new SqlCommand();
            _command.Connection = _connection;

        }

    }
Posted
Comments
[no name] 17-Sep-13 13:21pm    
It's not giving you an error because you are never executing the command.

Dear Developer,

You provided only the SQL command.

The following ExecuteQuery command is needed to execute the SQL.
C#
_command.BeginExecuteNonQuery();

with regards,

Sunil
 
Share this answer
 
v3
You don't execute you query here,that is the problem. You need to use _command.ExecuteNonQuery() after your insert statement.See some examples to clear it more:
how to insert record in asp.net using c#[^]
Inserting records in the database[^]
Insert, update and delete (C#)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900