You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to insert c#'s System.DataTime value into table and whose column type is timestamp time without zone. Please find my table structure and C# code below:
Table:
CREATETABLEpublic."TestingDetails"
(
"TestID"integerNOT NULL,
"TestName"text,
"TesterName"text,
"TotalCount"integer,
"SuccessCount"integer,
"FailureCount"integer,
"EndDate"timestamp without time zone,
"StartDate"timestamp without time zone,
CONSTRAINT"TestingDetails_pkey"PRIMARY KEY ("TestID"),
CONSTRAINT"TestingDetails_TestID_key" UNIQUE ("TestID")
)
WITH (
OIDS=FALSE
);
ALTERTABLE public."TestingDetails"
OWNER TO postgres;
C# code:
stringconnstring="Server=localhost;Port=5432;Database=test;User Id=postgres;Password=sync1694";// Making connection with Npgsql providerNpgsqlConnectionconn=newNpgsqlConnection(connstring);conn.Open();if(conn.State==System.Data.ConnectionState.Open){stringsql="SELECT * FROM public."TestingDetails" ";// data adapter making request from our connectionNpgsqlDataAdapterda=newNpgsqlDataAdapter(sql,conn);DataSetds=newDataSet();ds.Reset();// filling DataSet with result from NpgsqlDataAdapterda.Fill(ds);// since it C# DataSet can handle multiple tables, we will select firstint_TestID=0;string_TestName="test";string_TesterName="demo";DateTime_EndDate=DateTime.Now;DateTime_StartDate=DateTime.Now;int_TotalCount=10;int_SuccessCount=5;int_FailureCount=5;if(ds.Tables.Count>0){DataTabledt=ds.Tables[0];_TestID=dt.Rows.Count+1;}//new NpgsqlDateTime()//dt.//NpgsqlCommand command = new NpgsqlCommand("insert into public."TestingDetails" (TestID, TestName, TesterName, TotalCount, SuccessCount, FailureCount) values(" + _TestID + ",'" + _TestName + "','" + _TesterName + "'," +_TotalCount + "," + _SuccessCount + "," + _FailureCount + ")", conn);NpgsqlCommandcommand=newNpgsqlCommand("insert into public."TestingDetails" values(:_TestID,:_TestName,:_TesterName,:_TotalCount,:_SuccessCount,:_FailureCount,:_StartDate)",conn);command.Parameters.Add(newNpgsqlParameter("_TestID",_TestID));command.Parameters.Add(newNpgsqlParameter("_TestName",_TestName));command.Parameters.Add(newNpgsqlParameter("_TesterName",_TesterName));command.Parameters.Add(newNpgsqlParameter("_StartDate",_StartDate));command.Parameters.Add(newNpgsqlParameter("_TotalCount",_TotalCount));command.Parameters.Add(newNpgsqlParameter("_SuccessCount",_SuccessCount));command.Parameters.Add(newNpgsqlParameter("_FailureCount",_FailureCount));command.Parameters.Add(newNpgsqlParameter("_EndDate",_EndDate));command.ExecuteNonQuery();}
The text was updated successfully, but these errors were encountered:
@sarath22 As mentioned previously, this issue needs to be opened in the repository for the ADO.NET driver: https://github.com/npgsql/npgsql. This repository is strictly concerned with the EF Core provider for Npgsql.
I'm trying to insert c#'s
System.DataTime
value into table and whose column type istimestamp time without zone
. Please find my table structure and C# code below:Table:
C# code:
The text was updated successfully, but these errors were encountered: