2016-03-05 54 views

回答

0

正如你可以試試這個:

SqlConnection sqlConnection = new SqlConnection(ConnString)) 
SqlCommand sqlCommand = new SqlCommand() 
sqlCommand.Connection = sqlConnection; 
sqlConnection.Open(); 

for(int i=0; i< myDataGridView.Rows.Count;i++) 
{ 
     query= @"INSERT INTO tableName VALUES (" 
       + ddlConsumidorFinalId.SelectedValue + ", " 
       + myDataGridView.Rows[i].Cells["ColumnName"].Value +", " 
       + myDataGridView.Rows[i].Cells["ColumnName"].Value +");"; 
        //Add as pre table fields 
       sqlCommand.CommandText = query; 
       sqlCommand.ExecuteNonQuery(); 
} 

如需更多信息,See this

相關問題