Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在按钮上单击“从表中的多个控件插入多个文本”(文本框和标签)_C#_Mysql_Sql_.net_Sql Server Ce - Fatal编程技术网

C# 在按钮上单击“从表中的多个控件插入多个文本”(文本框和标签)

C# 在按钮上单击“从表中的多个控件插入多个文本”(文本框和标签),c#,mysql,sql,.net,sql-server-ce,C#,Mysql,Sql,.net,Sql Server Ce,我已经创建了表“TenoOperations”,它有4列“EUR”类型real,“Rate”类型real,“BGN”类型real,“Date”类型nvarchar 在按钮上单击“我试图插入所有填充的文本框和标签中的数据”,以便: 第一排应该是 textbox1.text , Rate , textbox2.text , Date2.text textbox3.text , Rate , textbox4.text , Date4.text 第二排应该是 textbox1.text ,

我已经创建了表“TenoOperations”,它有4列“EUR”类型real,“Rate”类型real,“BGN”类型real,“Date”类型nvarchar

在按钮上单击“我试图插入所有填充的文本框和标签中的数据”,以便:

第一排应该是

 textbox1.text , Rate , textbox2.text , Date2.text
 textbox3.text , Rate , textbox4.text , Date4.text
第二排应该是

 textbox1.text , Rate , textbox2.text , Date2.text
 textbox3.text , Rate , textbox4.text , Date4.text
等等

Rate是全局双变量,Date2是标签,当textbox2.text发生更改时,它会更改文本

问题是,我的代码创建了无限多个值相等的行

private void InsertData_Click(object sender, EventArgs e)
{
            var textboxes = new List<TextBox>() {
                textBox1,
                textBox2,
                textBox3,
                textBox4,
                textBox5,
                textBox6,
                textBox7,
                textBox8,
                textBox9,
                textBox10,
                textBox11,
                textBox12,
                textBox13,
                textBox14,
                textBox15,
                textBox16,
                textBox17,
                textBox18,
                textBox19,
                textBox20
            };
            var labels = new List<Label>() {
                Date2,
                Date4,
                Date6,
                Date8,
                Date10,
                Date12,
                Date14,
                Date16,
                Date18,
                Date20        
            };

            SqlCeConnection connection = new SqlCeConnection(@"Data Source=C:\Users\FluksikartoN\Documents\Visual Studio 2012\Projects\BuroFoki\BuroFoki\MainDB.sdf");
            connection.Open();

            for (int i = 0; i < 10 ; i = i++)
            { 

                using (SqlCeCommand com = new SqlCeCommand("INSERT INTO TenOperations (EUR, Rate, BGN, Date) Values(@EUR, @Rate, @BGN, @Date)", connection))
                {


                    com.Parameters.AddWithValue("@EUR", textboxes[i+1].Text.ToString());
                    com.Parameters.AddWithValue("@Rate", EURbuy);
                    com.Parameters.AddWithValue("@BGN", textboxes[i].Text.ToString());
                    com.Parameters.AddWithValue("@Date", labels[i].Text.ToString());

                    com.ExecuteNonQuery();
                }
            }
            connection.Close();
        }
private void InsertData\u单击(对象发送方,事件参数e)
{
var textboxs=新列表(){
文本框1,
文本框2,
文本框3,
文本框4,
文本框5,
文本框6,
文本框7,
文本框8,
文本框9,
文本框10,
文本框11,
文本框12,
文本框13,
文本框14,
文本框15,
textBox16,
文本框17,
文本框18,
文本框19,
文本框20
};
变量标签=新列表(){
日期2,
日期4,
日期6,
日期8,
日期10,
日期12,
日期14,
日期16,
日期18,
日期20
};
SqlCeConnection connection=newsqlceconnection(@“数据源=C:\Users\FluksikartoN\Documents\visualstudio 2012\Projects\BuroFoki\BuroFoki\MainDB.sdf”);
connection.Open();
对于(int i=0;i<10;i=i++)
{ 
使用(SqlCeCommand com=new SqlCeCommand(“插入到TENOoperations(EUR,Rate,BGN,Date)值(@EUR,@Rate,@BGN,@Date)”,连接))
{
com.Parameters.AddWithValue(“@EUR”,文本框[i+1].Text.ToString());
com.Parameters.AddWithValue(“@Rate”,欧元);
com.Parameters.AddWithValue(“@BGN”,文本框[i].Text.ToString());
com.Parameters.AddWithValue(“@Date”,标签[i].Text.ToString());
com.ExecuteNonQuery();
}
}
connection.Close();
}
用于(int i=0;i<10;i=i++)
应该是

for (int i = 0; i < 10 ;i++)
for(int i=0;i<10;i++)

考虑使用
DataGridView
而不是乘法控件