使用asp.net c#不将新记录保存到MS sql数据库中 [英] Not Saving New Record Into MS sql database using asp.net c#

查看:71
本文介绍了使用asp.net c#不将新记录保存到MS sql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我的代码是不是使用asp.net c#插入/保存新记录进入我的sql数据库并且没有给我任何错误!



这里是我的代码:

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 :

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;

        }

    }

推荐答案

亲爱的开发者,



您只提供了SQL命令。



以下 ExecuteQuery 命令需要执行SQL。

Dear Developer,

You provided only the SQL command.

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



问候,



Sunil


with regards,

Sunil


这里没有执行查询,这就是问题所在。您需要在插入语句后使用 _command.ExecuteNonQuery()。请参阅一些示例以清除它:

如何使用c#在asp.net中插入记录 [ ^ ]

在数据库中插入记录 [ ^ ]

插入,更新和删除(C#) [ ^ ]
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#)[^]


这篇关于使用asp.net c#不将新记录保存到MS sql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆