Converting a DataTable to CSV
{
string strCSV = "";
string strSeperator = "";
foreach(DataColumn dc in dt.Columns)
{
strCSV += strSeperator + dc.ColumnName;
strSeperator = ",";
}
strCSV += "rn";
foreach(DataRow dr in dt.Rows)
{
strSeperator = "";
foreach(DataColumn dc in dt.Columns)
{
strCSV += strSeperator + dr[dc.ColumnName].ToString();
strSeperator = ",";
}
strCSV += "rn";
}
return strCSV;
}
SQL sever 2005 Management studio express
Error Number: -1
Severity: 20
State: 0
Program Location:
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection(UIConnectionInfo ci, IServerType server)
at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()
Resource files for Classic ASP
<data name="Hello!">
Ciao!
</data>
</root>
Set xmlResx=Server.CreateObject("Microsoft.XMLDOM")
xmlResx.async=false
xmlResx.load(Server.MapPath(ResourceFile))
End Function
Function Translate(english)
Set objLst = xmlResx.getElementsByTagName("data")
For i = 0 to (objLst.length -1)
EnglishText = objLst.item(i).attributes.getNamedItem("name").text
If english=EnglishText Then
Translate= objLst.item(i).text
Exit For
End If
Next
End Function
ASP.NET Crash on “OnBubbleEvent”
Capturing a webcam to an AVI file
SendMessage(lwndC, WM_CAP_FILE_SAVEDIB, 0&, filename)
End Sub
Where WM_CAP_FILE_SAVEDIB is defined as WM_USER+25
– It also requires an overloaded SendMessage declaration, which accepts a string as it’s final parameter.
I then found some CS code which converts BMP files to AVI (http://midget3d.com/gabe/AviLib.zip)
then used this to write bitmaps to disk, and build them into an AVI
saveFileDialog.Filter="*.avi|*.avi";
saveFileDialog.ShowDialog();
string strAVI = saveFileDialog.FileName;
string strBMP = saveFileDialog.FileName.Replace(".avi",".bmp");
AviWriter aviWriter =
new AviWriter(strAVI, AviCompression.None, 24, 320, 240);
isRecording =
true;
while(isRecording)
{
webcamControl1.SaveBitmap(strBMP);
aviWriter.WriteFrame(
new Bitmap(strBMP));
Application.DoEvents();
}
aviWriter.Close();
Compress an AVI movie using C#
private
bool ConvertToQuickTime(AxQTOControlLib.AxQTControl Control,string fromFileName,string toFileName){
this.axQTControl1.URL = fromFileName; if (!axQTControl1.Movie.CanExport) return false;QTOLibrary.QTQuickTime qt;
qt = axQTControl1.QuickTime;
if (qt.Exporters.Count == 0) qt.Exporters.Add();QTOLibrary.QTExporter exp;
exp = qt.Exporters[1];
// Set exporter type: AVI, 3G, MPEG-4, PNG, etc.exp.TypeName = "QuickTime Movie";
exp.SetDataSource(axQTControl1.Movie);
exp.DestinationFileName = toFileName;
exp.ShowProgressDialog =
true;exp.BeginExport();
return true;}
Converting a DataTable to a Hashtable
private
Hashtable convertDataTableToHashTable(DataTable dtIn,string keyField,string valueField){
Hashtable htOut =
new Hashtable(); foreach(DataRow drIn in dtIn.Rows){
htOut.Add(drIn[keyField].ToString(),drIn[valueField].ToString());
}
return htOut;}
Parsing WindJet routes
private
string GetWindJetRoutes(string HTML){
string outRoutes = ""; // Step 1. Delete between FL_Departure> and /SELECT string strOutboundRoutes = DeleteBetween(HTML,"FL_Departure>","/SELECT");MatchCollection mcDepIata = Regex.Matches(strOutboundRoutes,"value=(?<FromIata>[A-Z]{3})");
// Step 2. extract ToIata Array string strRegex = @"arrayVoli[(?<IDFrom>d+)][(?<IDTo>d+)]=new.Option(‘w.*'(?<ToIata>w{3})";MatchCollection mcDestIata = Regex.Matches(HTML,strRegex);
for(int iMatch=0;iMatch<mcDestIata.Count;iMatch++){
int intIDFrom = Convert.ToInt32(mcDestIata[iMatch].Groups["IDFrom"].Value); string strFromIata = mcDepIata[intIDFrom-1].Groups["FromIata"].Value; string strToIata = mcDestIata[iMatch].Groups["ToIata"].Value;outRoutes += "’" + strFromIata + "’,’" + strToIata + "’rn";
}
return outRoutes;}
Might be of interest to someone out there…. (or if not, my own personal reference)
Sage Data Objects for .NET
Interop.SageDataObject111.SageDataObjects sdo =
new Interop.SageDataObject111.SageDataObjects();Interop.SageDataObject111.WorkSpace wsStock;
Interop.SageDataObject111.StockRecord srStock;
wsStock = sdo.GetWorkSpace();
string strACCData = @"C:Program FilesSageAccountsACCDATA";wsStock.Connect(strACCData, "MANAGER", "", "ThisIsUnique");
srStock = (StockRecord)wsStock.CreateObject("StockRecord");
srStock.MoveFirst();
object objDescription = (object)"DESCRIPTION"; string strDescription = srStock.Fields.Item(ref objDescription).Value.ToString();MessageBox.Show(strDescription);
wsStock.Disconnect();
Object model is still quite messy. Going to try to clean that up, and put some decent help files together.