Click here to Skip to main content
15,887,972 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Finding a Row in a Datatable and putting the row to variables Pin
Andy_L_J15-Nov-12 19:48
Andy_L_J15-Nov-12 19:48 
GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
JRHibner18-Nov-12 16:15
JRHibner18-Nov-12 16:15 
AnswerRe: Finding a Row in a Datatable and putting the row to variables Pin
Andy_L_J18-Nov-12 20:45
Andy_L_J18-Nov-12 20:45 
GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
JRHibner18-Nov-12 20:55
JRHibner18-Nov-12 20:55 
GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
Andy_L_J18-Nov-12 21:33
Andy_L_J18-Nov-12 21:33 
GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
JRHibner18-Nov-12 21:36
JRHibner18-Nov-12 21:36 
GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
JRHibner27-Nov-12 19:28
JRHibner27-Nov-12 19:28 
AnswerRe: Finding a Row in a Datatable and putting the row to variables Pin
Andy_L_J27-Nov-12 20:56
Andy_L_J27-Nov-12 20:56 
Check this out:

VB.NET
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Dim dt As New DataTable
		With dt
			.Columns.Add("Id")
			.Columns.Add("Name")
			.Columns.Add("Address")
			.Columns.Add("Salary")


			.Rows.Add(New Object() {1, "John", "123 Some Street", 1234})
			.Rows.Add(New Object() {Nothing, "Sally", "26 This Street", Nothing})
			.Rows.Add(New Object() {3, "Frank", "15 TheOther Street", 1400})
			.Rows.Add(New Object() {4, "Harry", "3 No Street", 450})


		End With

		Dim dr As DataRow = GetDataRow(dt, "Sally")

		Dim id As Integer = -1
		If Not TypeOf (dr("Id")) Is DBNull Then
			id = CInt(dr("Id"))
		End If

		Try
			Label1.Text = String.Format("ID = {0}{4}Name = {1}{4}Address = {2}{4}Salary = {3}", id.ToString,
                                                          dr("Name").ToString, dr("Address").ToString, dr("Salary").ToString, vbCrLf)
		Catch ex As Exception

		End Try



		Label2.Text = String.Format("Field 0 contains: {0}", dr(0).GetType)
		If (TypeOf (dr("Id")) Is DBNull) Then
			Label3.Text = "DBNull in Field 0"
		End If

	End Sub

	Private Function GetDataRow(ByVal dt As DataTable, ByVal name As String) As DataRow
		Dim sStringTemp2 = "Name = '" + name + "'"
		Dim tRow As DataRow() = dt.Select(sStringTemp2)
		Return tRow(0)

	End Function
End Class

Notice that I used TypeOf to check the DataType in the Field and I used GetType() to return the Type.
I don't speak Idiot - please talk slowly and clearly

"I have sexdaily. I mean dyslexia. Fcuk!"

Driven to the arms of Heineken by the wife

GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
JRHibner27-Nov-12 23:40
JRHibner27-Nov-12 23:40 
GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
Andy_L_J28-Nov-12 0:20
Andy_L_J28-Nov-12 0:20 
GeneralRe: Finding a Row in a Datatable and putting the row to variables Pin
JRHibner28-Nov-12 10:35
JRHibner28-Nov-12 10:35 
QuestionChanging Assembly Properties through Reflection Pin
Dominick Marciano14-Nov-12 9:38
professionalDominick Marciano14-Nov-12 9:38 
AnswerRe: Changing Assembly Properties through Reflection Pin
Eddy Vluggen15-Nov-12 1:18
professionalEddy Vluggen15-Nov-12 1:18 
GeneralRe: Changing Assembly Properties through Reflection Pin
Dominick Marciano15-Nov-12 17:14
professionalDominick Marciano15-Nov-12 17:14 
GeneralRe: Changing Assembly Properties through Reflection Pin
Eddy Vluggen16-Nov-12 0:06
professionalEddy Vluggen16-Nov-12 0:06 
Questionmessagebeep Pin
Gil Goodridge14-Nov-12 8:00
Gil Goodridge14-Nov-12 8:00 
AnswerRe: messagebeep Pin
Dave Kreskowiak14-Nov-12 8:31
mveDave Kreskowiak14-Nov-12 8:31 
QuestionRijndael encryption not working Pin
maskrtnik0114-Nov-12 2:20
maskrtnik0114-Nov-12 2:20 
AnswerRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 2:52
professionalKeith Barrow14-Nov-12 2:52 
GeneralRe: Rijndael encryption not working Pin
maskrtnik0114-Nov-12 3:08
maskrtnik0114-Nov-12 3:08 
GeneralRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 3:26
professionalKeith Barrow14-Nov-12 3:26 
GeneralRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 3:35
professionalKeith Barrow14-Nov-12 3:35 
GeneralRe: Rijndael encryption not working Pin
maskrtnik0114-Nov-12 3:48
maskrtnik0114-Nov-12 3:48 
GeneralRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 4:05
professionalKeith Barrow14-Nov-12 4:05 
QuestionRe: Rijndael encryption not working Pin
maskrtnik0115-Nov-12 19:40
maskrtnik0115-Nov-12 19:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.