Showing posts with label dim. Show all posts
Showing posts with label dim. Show all posts

Wednesday, March 7, 2012

how to read from sql data set

Code Snippet

Dim ds As New DataSet

Dim adp As New SqlDataAdapter("Select MaxID,ValueName from tblSettings where ID=1", cn)

adp.Fill(ds)

If IsDBNull(ds.Tables(0).Columns("MaxID")) Then

GetMaxID = 1

Else

GetMaxID = ds.Tables(0).Columns("MaxID")

End If

the ds.Tables(0).Columns("MaxID") showing a value like this. ( Please tell how to read from sql data set)

{System.Data.DataColumn}

AllowDBNull: True

AutoIncrement: False

AutoIncrementSeed: 0

AutoIncrementStep: 1

Caption: "MAxid"

ColumnMapping: Element {1}

ColumnName: "MAxid"

Container: Nothing

DataType: {Name = "Decimal" FullName = "System.Decimal"}

DateTimeMode: UnspecifiedLocal {3}

DefaultValue: {System.DBNull}

DesignMode: False

Expression: ""

ExtendedProperties: Count = 0

MaxLength: -1

Namespace: ""

Ordinal: 0

Prefix: ""

ReadOnly: False

Site: Nothing

Table: {System.Data.DataTable}

Unique: False

Replace your SQL statement with this:

"Select isNull(MaxID, 1) As GetMaxID, ValueName from tblSettings where ID=1"

No need to check null value in your VB code.