2012-11-08 4 views
0

현재 사용자가 그리드에 데이터를 입력 한 다음이 데이터를 SQl 테이블에 삽입하는 응용 프로그램을 작성 중입니다. 그러나 맨 위에 행을 삽입하는 데 문제가 있습니다. 프로 시저에 대해 너무 많은 매개 변수가 선언되었다는 오류가 표시됩니다. 각 행에 삽입이 발생하는 루프를 실행하려고합니다. 상단 행이 삽입되어 실행되지만 다른 아무것도VB.Net SQL Data insert from insert

For i = 0 To dgvRI.Rows.Count - 1 
      sqlRI.CommandText = "dbo.vb_insert" 
      sqlRI.CommandType = CommandType.StoredProcedure 
      sqlRI.Parameters.Add("@accid", SqlDbType.VarChar).Value = accid 
      sqlRI.Parameters.Add("@rnum", SqlDbType.Int).Value = dgvRI.Rows(i).Cells(0).Value 
      sqlRI.Parameters.Add("@rilim", SqlDbType.Decimal).Value = dgvRI.Rows(i).Cells(1).Value 
      sqlRI.Parameters.Add("@riatt", SqlDbType.Decimal).Value = dgvRI.Rows(i).Cells(2).Value 
      sqlRI.Parameters.Add("@rishare", SqlDbType.Decimal).Value = dgvRI.Rows(i).Cells(3).Value 
      sqlRI.Parameters.Add("@rname", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(4).Value 
      sqlRI.Parameters.Add("@bname", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(5).Value 
      sqlRI.Parameters.Add("@type", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(6).Value 
      sqlRI.Parameters.Add("@cov", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(7).Value 
      sqlRI.Parameters.Add("@prop", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(8).Value 
      sqlRI.Parameters.Add("@loc", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(9).Value 
      sqlRI.Parameters.Add("@con", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(10).Value 
      sqlRI.Parameters.Add("@prem", SqlDbType.Decimal).Value = dgvRI.Rows(i).Cells(11).Value 
      sqlRI.Parameters.Add("@curr", SqlDbType.VarChar).Value = dgvRI.Rows(i).Cells(12).Value 
      i += sqlRI.ExecuteNonQuery() 
     Next 
    Catch ex As Exception 
     MessageBox.Show(ex.Message) 
    End Try 

답변

0

은 각 행에 대해 새로운 인스턴스를 생성 무시하면 , 난 당신이 같은 PARAM 매번를 추가 객체 생각합니다.

 sqlRI = new sqlRI();//create new instance everytime 
     sqlRI.CommandText = "dbo.vb_insert" 
     sqlRI.CommandType = CommandType.StoredProcedure 
     sqlRI.Parameters.Add("@accid", SqlDbType.VarChar).Value = accid