2013-08-17 164 views
1

我遇到了問題我是.net應用程序的普通開發人員,因爲我之前在PHP中工作。通過ODBC將數據表直接插入到Postgre數據庫

我想直接通過ODBC在.NET語言中插入填充數據表,以數據庫爲C#

誰能幫我做這個。

謝謝你這麼多

if (_DataTable1.Rows.Count > 0) 
     { 
      int j=0; 
      for(int i =0 ; i < _DataTable1.Rows.Count ; i ++){     
       query = "Select * from Cards where ecode='" + _DataTable1.Rows[i]["ecode"] + "'"; 
       _DataTable2 = CentralConn.Select(query); 
       if (_DataTable2.Rows.Count > 0) 
       { 
        _DataTableUpdate.Rows.Add(DUpdateRow); 
        foreach (string name in Enum.GetNames(typeof(LocalToCentralFields))) 
        { 
         _DataTableUpdate.Rows[j][name] = _DataTable1.Rows[i][name]; 
        } 
        j++; 
       } 
       else { 
        _DataTableInsert.Rows.Add(DInsertRow); 
        foreach (string name in Enum.GetNames(typeof(LocalToCentralFields))) 
        { 
         _DataTableInsert.Rows[j][name] = _DataTable1.Rows[i][name]; 
        } 
        j++; 
       } 


      } 

CentralConn.TransactionInsertion(_DataTableInsert);對於TransactionInsertion

public void TransactionInsertion(DataTable DT,string TableName) 
    { 

     OdbcCommand Command = connection.CreateCommand(); 
     Command.CommandText = "Insert"; 
     Transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted); 

     OdbcDataAdapter Adapter = new OdbcDataAdapter(); 
     Adapter.InsertCommand = new OdbcCommand(); 



    } 

我困在這裏

//代碼一點點做什麼..請指導

回答

1

看一看.Net Data Provider for Postgresql

,更具體的功能

// Setups the insert command. 
public void insertCmd() 
{ 
    string insertQuery = "INSERT INTO npdata VALUES (@key, @ndata)"; 
    NpAdapter.InsertCommand = new NpgsqlCommand(insertQuery, conn); 

    NpParam = NpAdapter.InsertCommand.Parameters.Add("@key", NpgsqlTypes.NpgsqlDbType.Text); 
    NpParam.SourceColumn = "key"; 
    NpParam.SourceVersion = DataRowVersion.Current; 

    NpParam = NpAdapter.InsertCommand.Parameters.Add("@ndata", NpgsqlTypes.NpgsqlDbType.Bigint); 
    NpParam.SourceVersion = DataRowVersion.Current; 
    NpParam.SourceColumn = "ndata"; 

} 
+0

我工作的應用程序是用vb6編寫的,它的目的是應用程序是將不同門上生成的電子卡同步到中央數據庫。我用.NET 4.0重寫了C#中的代碼。 –

+0

我已編輯過帖子,請檢查@astander –

相關問題