dataGridView非绑定数据源如何保存到数据库

请老师帮忙解决我一个难题,现dataGridView自定义comboBox和textBox列,输入数据后
想把输入的数据保存到数据库表里,求C#代码

可以拿到dataGridView行修改事件,根据事件得到修改项,得到的json通过POST传递保存,这个和C#语言无关

请提供代码看看,谢谢!

Ext.define('weichai.app.view.AddNumWindow', {
extend: 'Ext.window.Window',
alias: 'widget.addnumwindow',

requires: [
    'weichai.app.view.AddNumWindowViewModel',
    'Ext.form.field.Text',
    'Ext.button.Button',
    'Ext.form.Panel',
    'Ext.grid.Panel',
    'Ext.grid.column.Column',
    'Ext.grid.View',
    'Ext.selection.CheckboxModel',
    'Ext.toolbar.Paging',
    'Ext.form.field.Hidden',
    'Ext.toolbar.Fill',
    'Ext.toolbar.Separator'
],

viewModel: {
    type: 'addnumwindow'
},
defaultListenerScope: true,
autoShow: true,
height: 620,
id: 'AddNumWindow',
width: 820,
title: '新增标准任务编号',

layout: {
    type: 'vbox',
    align: 'stretch'
},
items: [
    {
        xtype: 'panel',
        height: 100,
        id: 'addNumForm',
        layout: 'absolute',
        bodyPadding: 10,
        items: [
            {
                xtype: 'textfield',
                x: 20,
                y: 20,
                id: 'st_name',
                width: 300,
                fieldLabel: '标准任务名称',
                labelWidth: 90,
                name: 'st_name'
            },
            {
                xtype: 'textfield',
                x: 340,
                y: 20,
                id: 'st_base_id',
                width: 300,
                fieldLabel: '基础任务编号',
                labelWidth: 90,
                name: 'st_base_id'
            },
            {
                xtype: 'textfield',
                x: 20,
                y: 60,
                id: 'dep_name',
                width: 300,
                fieldLabel: '责任科室',
                labelWidth: 90,
                name: 'dep_name'
            },
            {
                xtype: 'button',
                x: 340,
                y: 60,
                width: 80,
                text: '搜索',
                listeners: {
                    click: 'onButtonClickQuery'
                }
            }
        ]
    },
    {
        xtype: 'form',
        flex: 1,
        id: 'gridForm',
        title: '标准任务编号列表',
        items: [
            {
                xtype: 'gridpanel',
                autoScroll: true,
                height: 408,
                id: 'stidGrid',
                title: '',
                enableColumnHide: false,
                columns: [
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'stid',
                        text: '标准任务编号',
                        flex: 1
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'stname',
                        text: '标准任务名称',
                        flex: 1
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'stcname',
                        text: '所属分类',
                        flex: 1
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'stbaseid',
                        text: '基础任务编号',
                        flex: 1
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'stbasename',
                        text: '基础任务名称',
                        flex: 1
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'depname',
                        text: '责任科室',
                        flex: 1
                    }
                ],
                selModel: {
                    selType: 'checkboxmodel',
                    listeners: {
                        select: 'onCheckboxModelSelect',
                        deselect: 'onCheckboxModelDeselect'
                    }
                },
                dockedItems: [
                    {
                        xtype: 'pagingtoolbar',
                        dock: 'bottom',
                        id: 'pagingtoolBar',
                        width: 360,
                        displayInfo: true
                    }
                ]
            },
            {
                xtype: 'hiddenfield',
                anchor: '100%',
                id: 'docid',
                fieldLabel: 'Label',
                name: 'docid'
            }
        ]
    },
    {
        xtype: 'hiddenfield',
        flex: 1,
        id: 'stids',
        fieldLabel: 'Label',
        name: 'stids',
        value: ''
    }
],
dockedItems: [
    {
        xtype: 'toolbar',
        flex: 1,
        dock: 'bottom',
        items: [
            {
                xtype: 'tbfill'
            },
            {
                xtype: 'button',
                text: '<font style="color:black" >保存</font>',
                listeners: {
                    click: 'onButtonClick2'
                }
            },
            {
                xtype: 'tbseparator'
            },
            {
                xtype: 'button',
                text: '<font style="color:black" >取消</font>',
                listeners: {
                    click: 'onButtonClick1'
                }
            }
        ]
    }
],

onButtonClickQuery: function(button, e, eOpts) {
     var stname = Ext.getCmp('st_name').getValue();
     var stbaseid = Ext.getCmp('st_base_id').getValue();
     var depname = Ext.getCmp("dep_name").getValue();
    //alert("1111"+stname+stbaseid+depname);
    var store = Ext.getCmp('stidGrid').store;
    //alert(store);
    var g_service_base = "/imeWeb/Services/";
    store.proxy.url=g_service_base+"weichai/searchStidsByStname?stname="
            +stname+"&stbaseid="+stbaseid+"&depname="+depname;
            store.load();
},

onCheckboxModelSelect: function(rowmodel, record, index, eOpts) {
    var stidsField =Ext.getCmp('stids');
    var stids=stidsField.getValue();
    if(record !==''){
        var rec = record.get('stid')+'/';
        //init里面返回前一页时,会进行已选择的再选择一遍,遍历一下有没有,没有再加到stids里
        if(stids.indexOf(rec) === -1){
            stids=stids+rec;
            stidsField.setValue(stids);
        }

    }
    //alert(stidsField.getValue());
},

onCheckboxModelDeselect: function(rowmodel, record, index, eOpts) {
    //可以用hiddenfield定义全局变量
    //把stids控件获取到
    var stidsField =Ext.getCmp('stids');
    //获取到stids的值
    var stids=stidsField.getValue();
    //判断是否传进实参record
    if(record !==''){
        //根据dataindex获取属性值
        var rec = record.get('stid')+'/';
        //把获取到的值从stids中去掉
    stids =stids.replace(rec,"");
    }
    //将最后的stids赋值给hiddenfield
    stidsField.setValue(stids);
    //alert(stidsField.getValue());
},

onButtonClick2: function(button, e, eOpts) {
                // //得到选择
                // var grid=Ext.getCmp('stidGrid');
                // var selected = grid.getSelectionModel().selected;
                // //未选中报错
                // if(selected.getCount()<1){
                //     //Ime.getApplication().log('ERROR', "请选中至少一条记录!");此种方法行不通
                //     alert("请选中至少一条记录!");
                //     return;
                // }
    //把init函数里的docid获取到,获取不到就报错
    var docid = Ext.getCmp('docid').getValue();
    //alert(docid);
    if(docid===null||docid===''){
        Ext.MessageBox.alert(i18n.error,i18n.requireNum);
        return;
     }
    //把stids控件获取到
    var stidsField =Ext.getCmp('stids');
    //获取到stids的值
    var stids=stidsField.getValue();
                // //遍历出标准任务编号
                //     var selectids="";
                //     for(var p=0;p<selected.getCount();p++){
                //     selectids=selectids+selected.get(p).get("stid")+"/";
                //     }
                //     alert(selectids);
                // alert(typeof(selectids));
        stids=stids.substring(0,(stids.length-1));
        alert(stids);
    var form = Ext.getCmp('gridForm');
    if(!form.isValid()){
        Ext.MessageBox.alert(i18n.info,i18n.fieldisnull);
        return;
    }
    form.submit({

        method:'POST',
        params:{'selectids' : stids},
        url:g_url_serviceBase+"Services/weichai/addNum",
        waitMsg:i18n.waiting,
        success:function(f,v){
            var win = Ext.getCmp('AddNumWindow');
            Ext.MessageBox.alert(i18n.info,i18n.saveSuccess_workWaiting);
            win.close();
        },
        failure:function(f,v){
            Ext.MessageBox.alert(i18n.error,i18n.fail);
        }
    });
},

onButtonClick1: function(button, e, eOpts) {
    this.close();
},

init: function(docid) {
    var stidStore = Ext.create('Ext.data.Store', {
                        fields: [
                            {name: 'A1'},
                            {name: 'A2'},
                            {name: 'A3'},
                            {name: 'A4'},
                            {name: 'A5'},
                            {name: 'A6'}
                        ],

                        proxy: {
                            type: 'ajax',
                            reader: {
                                type: 'json',
                                rootProperty: 'records'
                            }
                        }
                    });
            var idgrid=Ext.getCmp('stidGrid');
            idgrid.setStore(stidStore);
    //pagingtoolbar和stidGrid共用stidStore
            var pagingtoolBar=Ext.getCmp('pagingtoolBar');
            pagingtoolBar.setStore(stidStore);
    //gridpanel加载完后执行事件
    stidStore.on("load",function(stidStore){
        if(stidStore.data.length>0){
            //alert(stidStore.data.length);
            //遍历出每条数据
            for(var k =0; k<stidStore.data.length; k++){
                var record =stidStore.getAt(k);
                var stid = record.get("stid");
                //alert(stid);
                //查找stid是否存在在hiddenvalue--stids的value里
                //把stids控件获取到
            var stidsField =Ext.getCmp('stids');
            //获取到stids的值
            var stids=stidsField.getValue();
                if(stids.indexOf(stid) > -1){
                    idgrid.getSelectionModel().select(record, true);
                }

            }
        }

        //alert(stidStore);
    });

    //store.on("load",function(store) {cSM.selectAll();});
    //获取docid
            var docid = docid;
            //alert(docid);
            Ext.getCmp('docid').setValue(docid);
            Ext.QuickTips.init();
}

});

把我的代码贴给你了,还是比较好懂,求赐最佳答案。

1、拼接成SQL语句,直接写进数据库,使用数据量小
2、使用存储过程存储,遍历datagridview,将每行每列用不同的符合区分开,合并成一个参数,传入后台,使用存储过程拆解,然后存入数据库