本帖最后由 think_1987 于 2009-11-24 15:43:35 编辑

解决方案 »

  1.   

    显示:
    Cnt.openConn();
                    conn = Cnt.getConn();
                    OracleCommand ocd = conn.CreateCommand();
                    ocd.CommandText = strsql;
                    OracleDataReader ord = ocd.ExecuteReader();               
                        while (ord.Read())
                        {
                            dataGridView_dcgrfhmx.Rows.Add(Convert.ToString(rowCount++), ord[1].ToString(), ord[2].ToString(), ord[3].ToString(), ord[4].ToString(), ord[0].ToString());
                        }
                   
    修改:
     private void submit_Click(object sender, EventArgs e)
            {
                int rowCount;//统计记录的条数,显示序列号
                rowCount = dataGridView_dcgrfhmx.Rows.Count;
                
                OracleConnection conn = new OracleConnection();   //创建一个新连接   
                string strsql;
                
                try
                {
                    Cnt.openConn();
                    conn = Cnt.getConn();
                    OracleCommand ocd = conn.CreateCommand();
                    ocd.CommandType = CommandType.Text;
                    
                    for (int i = 0; i < rowCount; i++)
                    {
                        if (dataGridView_dcgrfhmx.Rows[i].Cells[2].Value == null)
                            dataGridView_dcgrfhmx.Rows[i].Cells[2].Value = "";
                        if (dataGridView_dcgrfhmx.Rows[i].Cells[3].Value == null)
                            dataGridView_dcgrfhmx.Rows[i].Cells[3].Value = "";
                        if (dataGridView_dcgrfhmx.Rows[i].Cells[4].Value == null)
                            dataGridView_dcgrfhmx.Rows[i].Cells[4].Value = "";
                        strsql = "update tbl_dcgrfhmxb set HTPJGRL='"+dataGridView_dcgrfhmx.Rows[i].Cells[2].Value.ToString()+"', GRMJ='"+dataGridView_dcgrfhmx.Rows[i].Cells[3].Value.ToString()+"', BZ='"+dataGridView_dcgrfhmx.Rows[i].Cells[4].Value.ToString()+"'  where DCBM='"+dataGridView_dcgrfhmx.Rows[i].Cells[5].Value.ToString().Trim()+"'";
                        ocd.CommandText = strsql;
                        ocd.ExecuteNonQuery();
                        
                        
                    }
                     
                   ocd.Dispose();
                    Cnt.closeConn();//关闭连接                MessageBox.Show("修改完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);            }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                   
                }
              
                
            }这是oracle的代码,原理跟sql差不多,你借鉴下吧。