jump to navigation

Rolling DataTables by hand June 23 2004

Creating dataTables programatically is very handy. This is just a quick note to remind myself how to do it.

1. Create the new datatable

Dim dtblSalesLeads As New DataTable(”sales_leads”)

2. Create the columns

Dim dcolColumn As DataColumn
dcolColumn = New DataColumn(”sales_lead_id”, GetType(String))
dtblSalesLeads.Columns.Add(dcolColumn)

dcolColumn = New DataColumn(”sales_lead_datetime”, GetType(DateTime))

Dealing With DBNull values in a database June 21 2004

Just a quick note on how to deal with DBNull values when they are yanked from the DB.

Here is the Example :

Cast from type ‘DBNull’ to type ‘Integer’ is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Cast from type ‘DBNull’ to type ‘Integer’ is not valid.

Basically the value in the DB was null and I was trying to get an integer.

This is what you do:

dim …

Exporing Datagrids to Excel

Thanks to DOT Net John for this one

http://www.dotnetjohn.com/articles/articleid78.aspx

Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Response.Clear()
Response.Charset = “”
’set the response mime type for excel
Response.ContentType = “application/vnd.ms-excel”
‘create a string writer
Dim stringWrite As New System.IO.StringWriter
‘create an htmltextwriter which uses the stringwriter

Access Database Connection String June 18 2004

Connections to an access database can be a bitch.

I installed MDAC and JET SP8 and I still got the stupid ISAM error message!

Here is an example that I ripped off from the Visual Studio Solution Explorer:

Dim connection As New OleDbConnection(”Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=E:\AccessDB\SalesLead\Leads.mdb;Mode=Share Deny
None;Extended Properties=”"”";Jet OLEDB:System database=”"”";Jet OLEDB:Registry Path=”"”";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking
Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt
Database=False;Jet OLEDB:Don’t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False”)

Determining File Size June 11 2004

Public Shared Function getFileSize(ByVal strFileSystemPath As String) As Integer

Dim MyFileInfo As New FileInfo(strFileSystemPath)
Return (MyFileInfo.Length)

End Function

| older posts »