本文介绍了变量名"@Loan_id"已经声明.变量名称在查询批处理或存储过程中必须唯一.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String query = "insert into Installments(Loan_id,Date,Amount)values(@Loan_id,@Date,@Amount)";
            SqlCommand cmd = new SqlCommand(query, cn);
            cmd.Prepare();

            for (i = 0; i < dataGridView1.Rows.Count; i++)
            {
                cmd.Parameters.AddWithValue("@Loan_id", txtloanidofinstallmentform.Text);
                cmd.Parameters.AddWithValue("@Date", dataGridView1.Rows[i].Cells["Date"].Value);
                cmd.Parameters.AddWithValue("@Amount", dataGridView1.Rows[i].Cells["Amount"].Value);
            }

            cmd.ExecuteNonQuery();
            MessageBox.Show("record stored");




        }



添加了代码块[/编辑]



Code block added[/Edit]

推荐答案

String query = "insert into Installments(Loan_id,Date,Amount)values(@Loan_id,@Date,@Amount)";
SqlCommand cmd = new SqlCommand(query, cn);
cmd.Prepare();

for (i = 0; i < dataGridView1.Rows.Count; i++)
    {
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("@Loan_id", txtloanidofinstallmentform.Text);
    cmd.Parameters.AddWithValue("@Date", dataGridView1.Rows[i].Cells["Date"].Value);
    cmd.Parameters.AddWithValue("@Amount", dataGridView1.Rows[i].Cells["Amount"].Value);
    cmd.ExecuteNonQuery();
    }

MessageBox.Show("record stored");


这篇关于变量名"@Loan_id"已经声明.变量名称在查询批处理或存储过程中必须唯一.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 18:50