static void InsertRecord(ToCheck1 obj) { NpgsqlConnection con = new NpgsqlConnection("Server = 127.0.0.1; User Id = postgres; Password=postgres;Database=sportsweb;"); con.Open(); string TempInsertUninitializedItemSql = string.Format( "INSERT INTO {0}(SessionId, SessionItemLong, Timeout, Expires, Locked, LockDate, LockDateLocal, LockCookie, Flags)VALUES" + "(:{1}, :{2}, :{3}, :{4},0 :: bit, :{5}, :{6},1,1)", "ASPStateTempSessions", (object)SqlParameterName.SessionId, (object)SqlParameterName.SessionItemLong, (object)SqlParameterName.Timeout, (object)SqlParameterName.Expires, (object)SqlParameterName.LockDate, (object)SqlParameterName.LockDateLocal); var stream = SerializeObject(obj); var buff = stream.ToArray(); NpgsqlCommand cmd = new NpgsqlCommand(TempInsertUninitializedItemSql); cmd.Connection = con; cmd.Parameters.AddSessionIdParameter(SessionId1) .AddSessionItemLongParameter(Convert.ToInt32(stream.Length), buff) .AddTimeoutParameter(20) .AddLockDateParameter().AddLockDateLocalParameter(); cmd.ExecuteNonQuery(); }
public static MemoryStream SerializeObject(ToCheck1 item) { MemoryStream stream = new MemoryStream(); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, item); return(stream); }
static void Main(string[] args) { //NpgsqlConnection con = new NpgsqlConnection("Server = 127.0.0.1; User Id = postgres; Password=postgres;Database=sportswebtest;"); //con.Open(); //NpgsqlCommand cmd = new NpgsqlCommand("select * from aspstatetempsessions"); //cmd.Connection = con; string id = "9888333"; var itemtoInsert = new ToCheck1() { IntValue = 3, S1 = "My Check Value", booleanvalue = true, decValue = 3.90m, doubleValue = 8.409 }; // InsertRecord(itemtoInsert); // UpdateAndRead(); //ReadRecord(); GetStateItemExclusiveSql_Query(); }