Dariusz
Bujak
Student, młodszy
programista JAVA,
C++
Temat: C++/CLI i potgreSQL
WitamStawiam pierwsze kroki w połączeniu C++/CLI i potgreSQL, udało mi sie dodać rekord do bazy tylko że teraz potrzebował bym jego id, użyłem takiego kodu
void AddWithDataSet(NpgsqlConnection conn)
{ conn.Open();
DataSet ds = new DataSet();
NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from tableb", conn);
da.InsertCommand = new NpgsqlCommand("insert into tableb(field_int2, field_timestamp, field_numeric) " +
" values (:a, :b, :c)", conn);
da.InsertCommand.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Smallint));
da.InsertCommand.Parameters.Add(new NpgsqlParameter("b", NpgsqlDbType.Timestamp));
da.InsertCommand.Parameters.Add(new NpgsqlParameter("c", NpgsqlDbType.Numeric));
da.InsertCommand.Parameters[0].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[1].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[2].Direction = ParameterDirection.Input;
da.InsertCommand.Parameters[0].SourceColumn = "field_int2";
da.InsertCommand.Parameters[1].SourceColumn = "field_timestamp";
da.InsertCommand.Parameters[2].SourceColumn = "field_numeric";
da.Fill(ds);
DataTable dt = ds.Tables[0];
DataRow dr = dt.NewRow();
dr["field_int2"] = 4;
dr["field_timestamp"] = new DateTime(2003, 03, 03, 14, 0, 0);
dr["field_numeric"] = 7.3M;
dt.Rows.Add(dr);
DataSet ds2 = ds.GetChanges();
da.Update(ds2);
ds.Merge(ds2);
ds.AcceptChanges();
}
jest to w sumie przykład z tej strony:
http://npgsql.projects.postgresql.org/docs/manual/User...
Gdy by ktoś znał inny sposób dodawania do bazy to też prosze po wpis, ale najważniejsze jest dla mnie teraz pobranie tego id.
Przy okazji prosiłbym o podanie jak pobrać aktualną date ponieważ mam kolumne 'update_date' do której chciałbym wprowadzać wartość po każdej modyfikacji rekordu, typ rekordu to 'timestamp without time zone'.
Pozdrawiam.Dariusz Bujak edytował(a) ten post dnia 10.05.12 o godzinie 12:43