如何在asp.net中插入来自转发器的记录 [英] how to insert records from repeater in asp.net

查看:95
本文介绍了如何在asp.net中插入来自转发器的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



今天我正在为转发器工作,这是第一次。



因为,我正在从数据库SQL SERVER填充转发器。



该表包含车型,车牌号#,状态。



v-type n plate no#正在填充数据库。因为,如果db中有100辆车,那么它将按部门显示在插入页面上。



所以,如果我选择任何一个部门:它会显示那些许多车辆包括。



现在,问题是,如何插入部门的所有记录..



假设一个部门有10辆车然后我应该如何调用插入存储过程来执行那么多次。







plzzz ...建议我!

Hi Guys,

Today i'm working on repeater something like for the first time.

Because, i'm filling the repeater from the data base SQL SERVER.

the table consist of vehicle-type, plate no#, status.

v-type n plate no# are filling from the DB. Because, if there are 100 vehicles in db then it will display on the insertion page by department wise.

so, if i select any one dept: it will show those many vehicles that dept consist of.

Now, the problem is, how to insert all the record that dept.. have.

suppose one dept have 10 vehicles then how should i call the insertion stored procedure to execute those many times.



plzzz... suggest me!

推荐答案

参考


最好将数据库和网格视图填充代码移到单独的位置功能,以便轻松重复按钮点击操作。



例如,请查看示例代码:



It is always better to move the database and grid view filling codes to separate functions, so that it is easy to repeat the actions on button clicks.

For Example please go through the Sample code:

protected void btnInsert_Click(object sender, EventArgs e)
  {
    String connectionString = ConfigurationManager.ConnectionStrings["DbConnect"].ConnectionString;
    String queryString = "";
     using (SqlConnection connection = new SqlConnection(connectionString))
    {
        foreach (RepeaterItem item in Repeater1.Items)
       {
        TextBox Subject_Id = (TextBox)item.FindControl("Subject_Id");
        TextBox Subject_Name = (TextBox)item.FindControl("Subject_Name");
        TextBox Marks = (TextBox)item.FindControl("Marks");

        queryString = "Insert into result VALUES (id='"+@Subject_Id+"',name='"+@Subject_Name+"',marks='"+@Marks+"')";

        SqlCommand command = new SqlCommand(queryString, connection);

        // execute the query to update the database
        cmd.ExecuteNonQuery();
        }
    }
    //call the function to load the gridview if it is lost on postback.
  }


这篇关于如何在asp.net中插入来自转发器的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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