如何保存gridview记录到数据库 [英] how to save the gridview recordsto database

查看:70
本文介绍了如何保存gridview记录到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的运行模式如下





Gridview如下;



Facid 1 2 3 4 5



1 dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5

(好/公平/差)(好/公平/差(好/公平/差)(好/公平/差)(好/公平/差)



2 dropdownlist6 dropdownlist7 dropdownlist8 dropdownlist9 dropdownlist10

(良好/公平/差)(良好/公平/差)(良好/公平/差)(良好/公平/差)(良好/公平/差)





i想要将上面的gridview记录保存在数据库中。





在数据库表结构中如下



Facid R1 R2 R3 R4 R5



1好公平好公平好

2好公平好公平好



为什么我在asp.net中使用c#。

my run mode as follows


Gridview as follows;

Facid 1 2 3 4 5

1 dropdownlist1 dropdownlist2 dropdownlist3 dropdownlist4 dropdownlist5
(good/fair/poor) (good/fair/poor)(good/fair/poor) (good/fair/poor) (good/fair/poor)

2 dropdownlist6 dropdownlist7 dropdownlist8 dropdownlist9 dropdownlist10
(good/fair/poor) (good/fair/poor)(good/fair/poor) (good/fair/poor) (good/fair/poor)


i want to save the above gridview records in database.


In database table structure as follows

Facid R1 R2 R3 R4 R5

1 good fair good fair good
2 good fair good fair good

for that how can i do in asp.net using c#.

推荐答案

这是解决方案。请根据您的要求进行更改。



Here is the solution. Please make the changes as per your requirement.

using(SqlConnection connection = new SqlConnection(@"data source=ABC; persist security info=True;initial catalog=ini"))
{
    using(SqlCommand command = new SqlCommand(sql, connection))
    {
        try
        {
            connection.Open();
            for (int i =0; i< gridView1.RowCount; i++)
            {
                SqlParameter parameter = new SqlParameter();
                                parameter.ParameterName = "@Num";

                parameter.SqlDbType = SqlDbType.NVarChar;
                parameter.Direction = ParameterDirection.Input;
                parameter.Value = Convert.ToString(gridView1.GetRowCellValue(i, "Number"));


                command.Parameters.Add(parameter);
            }
            command.ExecuteNonQuery();
        }
        catch(Exception)
        {

        }

    }


}







干杯,

Praveen Nelge




Cheers,
Praveen Nelge


这是解决方案



link 1

link 2


这篇关于如何保存gridview记录到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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