This code should do the trick: using System; using System.Collections.Generic; using System.Text; using System.IO; using System.IO.Compression; namespace CompressDecompress { class Program { static void Main(string[] args) { string LstrTest = "This is a test"; string LstrOutput; LstrOutput = CompressString(LstrTest); LstrTest = DeCompressString(LstrOutput); Console.WriteLine(LstrTest); } public static string CompressString(string PstrInput) { MemoryStream Lms; GZipStream LstmZipStream; byte[] LbytBufIn; byte[] LbytBufOut; LbytBufIn = Encoding.UTF8.GetBytes(PstrInput); Lms = new MemoryStream(); LstmZipStream = new GZipStream(Lms, CompressionMode.Compress, false); LstmZipStream.Write(LbytBufIn, 0, LbytBufIn.Length); LbytBufOut = Lms.GetBuffer(); LstmZipStream.Close(); return Convert.ToBase64String(LbytBufOut); } public static string DeCompressString(string PstrInput) { MemoryStream Lms; GZipStream LstmZipStream; UTF8Encoding Lutf; byte[] LbytBufIn; byte[] LbytBufOut; int LintRead; LbytBufIn = Convert.FromBase64String(PstrInput); Lms = new MemoryStream(); Lms.Write(LbytBufIn, 0 , LbytBufIn.Length); Lms.Position = 0; LbytBufOut = new byte[LbytBufIn.Length]; LstmZipStream = new GZipStream(Lms, CompressionMode.Decompress); LintRead = LstmZipStream.Read(LbytBufOut, 0, LbytBufOut.Length); LstmZipStream.Close(); Lutf = new UTF8Encoding(); return Lutf.GetString(LbytBufOut, 0 , LintRead); } } }
Darell F Butch Jr
Posts
-
String compressing with System.IO.Compression -
assigning null valueOoooh, now I understand what you are doing. I believe you will have change you logic a little. The DBNull is only a database value. I believe if you change the code to the following this should solve you problem. DataSet Lds; SqlDataAdapter Lda; SqlCommandBuilder Lcb; object[] LaobjValues; string LstrQueryString; using (SqlConnection Lconn = new SqlConnection(@"Data Source=.\DA;Database=Testing;Integrated Security=SSPI")) { Lconn.Open(); LaobjValues = new object[2]; LaobjValues[0] = "5"; LaobjValues[1] = DBNull.Value; LstrQueryString = "Select TOP 0 * From Table1"; Lds = new DataSet(); Lda = new SqlDataAdapter(LstrQueryString, Lconn); Lcb = new SqlCommandBuilder(Lda); Lda.Fill(Lds); Lds.Tables[0].Rows.Add(LaobjValues[0], LaobjValues[1]); Lda.Update(Lds); }
-
assigning null valueI have tested both techniques and the database has the value: SqlCommand Lcomm; DataSet Lds; SqlDataAdapter Lda; SqlCommandBuilder Lcb; string LstrQueryString; LstrQueryString = "Insert into Table1 (id, name) values (1, NULL)"; using (SqlConnection Lconn = new SqlConnection(@"Data Source=.\DA;Database=Testing;Integrated Security=SSPI")) { Lconn.Open(); Lcomm = new SqlCommand(LstrQueryString, Lconn); Lcomm.ExecuteNonQuery(); LstrQueryString = "Select TOP 0 * From Table1"; Lds = new DataSet(); Lda = new SqlDataAdapter(LstrQueryString, Lconn); Lcb = new SqlCommandBuilder(Lda); Lda.Fill(Lds); Lds.Tables[0].Rows.Add(2, System.DBNull.Value); Lda.Update(Lds); }
-
VS2003 / Stored Procedures & SourceSafeIf you are using integrated VSS, you could try unbinding the project or solution and re-binding. I know we had this same issue and I believe this is how we solved it.
-
assigning null valueMake sure the table column is define as allowing nulls and doesn't have a default value specified.
-
How to make transparency layer for drawing above the textfield?One suggestion and a technique that I have used before is to use another form. On that form you can remove the boarder and set the transparent key. You can also set the Opacity to give a faded look. This technique requires a little more coding to handle but is easier then using APIs. That would be the other option; for that I think will need to get a book.