Click here to Skip to main content
15,886,362 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Browser Control Help Pin
Tad McClellan29-Jan-09 17:19
professionalTad McClellan29-Jan-09 17:19 
QuestionUsing Windows Xbox 360 controller with VB.net Pin
the fossil29-Jan-09 5:35
the fossil29-Jan-09 5:35 
AnswerRe: Using Windows Xbox 360 controller with VB.net Pin
Dave Kreskowiak29-Jan-09 18:23
mveDave Kreskowiak29-Jan-09 18:23 
GeneralRe: Using Windows Xbox 360 controller with VB.net Pin
the fossil30-Jan-09 2:30
the fossil30-Jan-09 2:30 
GeneralRe: Using Windows Xbox 360 controller with VB.net Pin
Kulf23-Apr-11 15:02
Kulf23-Apr-11 15:02 
GeneralRe: Using Windows Xbox 360 controller with VB.net Pin
the fossil23-Apr-11 22:12
the fossil23-Apr-11 22:12 
GeneralRe: Using Windows Xbox 360 controller with VB.net Pin
Kulf24-Apr-11 15:08
Kulf24-Apr-11 15:08 
QuestionDuplicate code - Unhandlable error Pin
Phantom71529-Jan-09 4:20
Phantom71529-Jan-09 4:20 
I am having a very strange problem. I have datagrids to view DB entries. The code I have included shows the initialization of the grid and the deletion sub. The first one works fine, so I copied the code and altered it slightly to work for a different form, but it shouldn't have made any difference. When I try to use the second one (Class TimeOff) it gives me:

An unhandled exception has occurred in your application......
....
Column 'DI' does not belong to table TimeOff.

All of the mapping names correspond correctly with the DB.

I am at wit's end! Frown | :( Sigh | :sigh: Cry | :(( Mad | :mad: Unsure | :~
Am willing to send entire files if I didn't post enough. Please help:

The one that does work...
Imports System.Data.OleDb
Imports System.Configuration

Public Class EmployeeView
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Private Const SELECT_STRING As String = "SELECT * FROM tblEmployees ORDER BY FirstName, LastName, Title, Region, WorkPhone"
	Private Const CONNECT_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=data.mdb "
	Private manipulatedrow As Integer

	' The DataSet that holds the data.
	Public Shared m_DataSet As DataSet
	Public myCaller As Calendar

#Region "Employee View Form Load"

	Private Sub EmployeeView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Dim data_adapter As OleDbDataAdapter
		Dim oledbcommand As OleDbCommand

		' Create the SqlDataAdapter.
		data_adapter = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)

		' Map Table to Employees.
		data_adapter.TableMappings.Add("Table", "Employees")

		' Fill the DataSet.
		m_DataSet = New DataSet
		data_adapter.Fill(m_DataSet)

		'Create a Grid Table Style. Map it to the "Employees" Table.
		Dim aGridTableStyle As New DataGridTableStyle
		aGridTableStyle.MappingName = "Employees"
		aGridTableStyle.AlternatingBackColor = Color.LightYellow

		'
		' Create GridColumnStyle objects for the grid columns 
		'
		Dim col_ID As New DataGridTextBoxColumn
		Dim col_FirstName As New DataGridTextBoxColumn
		Dim col_LastName As New DataGridTextBoxColumn
		Dim col_Title As New DataGridTextBoxColumn
		Dim col_Region As New DataGridTextBoxColumn
		Dim col_WorkPhone As New DataGridTextBoxColumn
		Dim col_HomePhone As New DataGridTextBoxColumn

		With col_ID
			.MappingName = "ID"
			.HeaderText = "ID"
			.Width = 0
		End With

		With col_FirstName
			.MappingName = "FirstName"
			.HeaderText = "First Name"
			.Width = 75
		End With

		With col_LastName
			.MappingName = "LastName"
			.HeaderText = "Last Name"
			.Width = 75
			.NullText = ""
		End With

		With col_Title
			.MappingName = "Title"
			.HeaderText = "Title"
			.Width = 100
		End With

		With col_Region
			.MappingName = "Region"
			.HeaderText = "Region"
			.Width = 46
		End With

		With col_WorkPhone
			.MappingName = "WorkPhone"
			.HeaderText = "Work Phone"
			.Width = 75
		End With

		With col_HomePhone
			.MappingName = "HomePhone"
			.HeaderText = "Home Phone"
			.Width = 0
		End With

		'Add the styles to the table
		With aGridTableStyle.GridColumnStyles
			.Add(col_ID)
			.Add(col_FirstName)
			.Add(col_LastName)
			.Add(col_Title)
			.Add(col_Region)
			.Add(col_WorkPhone)
			.Add(col_HomePhone)
		End With

		'Add the GridColumnStyles to the aGridTableStyle.
		DataGrid1.TableStyles.Add(aGridTableStyle)

		'Bind the DataGrid control to the Employees DataTable.
		DataGrid1.SetDataBinding(m_DataSet, "Employees")
		DataGrid1.Refresh()

		Dim c As DataGridTextBoxColumn
		For Each c In Me.DataGrid1.TableStyles(0).GridColumnStyles
			c.TextBox.ContextMenu = ContextMenu1
		Next

	End Sub

#End Region

	Private Sub ctxDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ctxDelete.Click, btnDelete.Click
		Dim choice As MsgBoxResult
		choice = MsgBox("Are you sure you want to delete " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 1) & " " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) & " from the database?", MsgBoxStyle.YesNo, "Delete Employee?")
		If choice = MsgBoxResult.Yes Then
			Dim data_adapter As OleDbDataAdapter

			Dim oledbcommand As OleDbCommand
			Dim oledbconnection As OleDbConnection

			Dim strSQL As String

			oledbconnection = New OleDbConnection(CONNECT_STRING)
			oledbcommand = New OleDbCommand
			oledbcommand.Connection = oledbconnection
			oledbcommand.Connection.Open()

			strSQL = "Delete from tblEmployees where ID = " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 0)

			oledbcommand.CommandText = strSQL
			Try
				oledbcommand.ExecuteNonQuery()
			Catch ex As OleDbException
				MsgBox(ex.Message)
			End Try
			oledbcommand.Connection.Close()

			data_adapter = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)

			' Map Table to Employees.
			data_adapter.TableMappings.Add("Table", "Employees")

			' Fill the DataSet.
			m_DataSet = New DataSet
			data_adapter.Fill(m_DataSet)

			' Bind the DataGrid control to the Employees DataTable.
			DataGrid1.SetDataBinding(m_DataSet, "Employees")
		End If

		DataGrid1.Refresh()
	End Sub
End Class


...and the one that doesn't. Any ideas?
Imports System.Data.OleDb
Imports System.Configuration

Public Class TimeOff
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Private Const SELECT_STRING As String = "SELECT * FROM tblTimeOff ORDER BY TOEmployee, Start"
	Private Const CONNECT_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=data.mdb"

	Public myCaller As Calendar
	Public Shared TO_DataSet As DataSet

	Private Sub TimeOff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Dim data_adapter2 As OleDbDataAdapter
		Dim oledbcommand2 As OleDbCommand

		' Create the SqlDataAdapter.
		data_adapter2 = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)

		' Map Table to Employees.
		data_adapter2.TableMappings.Add("Table", "TimeOff")

		' Fill the DataSet.
		TO_DataSet = New DataSet
		data_adapter2.Fill(TO_DataSet)

		'Create a Grid Table Style. Map it to the "Employees" Table.
		Dim aGridTableStyle As New DataGridTableStyle
		aGridTableStyle.MappingName = "TimeOff"

		'
		' Create GridColumnStyle objects for the grid columns 
		'
		Dim col_DI As New DataGridTextBoxColumn
		Dim col_Employee As New DataGridTextBoxColumn
		Dim col_StartDate As New DataGridTextBoxColumn
		Dim col_EndDate As New DataGridTextBoxColumn

		With col_DI
			.MappingName = "DI"
			.HeaderText = "ID"
			.Width = 20
		End With

		With col_Employee
			.MappingName = "TOEmployee"
			.HeaderText = "Employee"
			.Width = 100
			.Alignment = HorizontalAlignment.Center
		End With

		With col_StartDate
			.MappingName = "Start"
			.HeaderText = "Start Date"
			.Width = 80
			.Alignment = HorizontalAlignment.Center
		End With

		With col_EndDate
			.MappingName = "End"
			.HeaderText = "End Date"
			.Width = 80
			.Alignment = HorizontalAlignment.Center
		End With

		'Add the styles to the table
		With aGridTableStyle.GridColumnStyles
			.Add(col_DI)		'0
			.Add(col_Employee)  '1
			.Add(col_StartDate) '2
			.Add(col_EndDate)   '3
		End With

		'Add the GridColumnStyles to the aGridTableStyle.
		DataGrid1.TableStyles.Add(aGridTableStyle)

		'Bind the DataGrid control to the Employees DataTable.
		Try
			DataGrid1.SetDataBinding(TO_DataSet, "TimeOff")
		Catch ex As Exception
			MsgBox(ex)
		End Try
		DataGrid1.Refresh()

		Dim c As DataGridTextBoxColumn
		For Each c In Me.DataGrid1.TableStyles(0).GridColumnStyles
			c.TextBox.ContextMenu = ContextMenu1
		Next

	End Sub

	Private Sub mnuDelEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDelEntry.Click
		Dim choice As MsgBoxResult
		Try
			choice = MsgBox("Are you sure you want to delete " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 1) & ": " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) & "-" & DataGrid1.Item(DataGrid1.CurrentRowIndex, 3) & " from the database?", MsgBoxStyle.YesNo, "Delete Employee?")
			If choice = MsgBoxResult.Yes Then
				Dim data_adapter2 As OleDbDataAdapter
				Dim oledbcommand2 As OleDbCommand
				Dim oledbconnection As OleDbConnection

				Dim strSQL As String

				oledbconnection = New OleDbConnection(CONNECT_STRING)
				oledbcommand2 = New OleDbCommand
				oledbcommand2.Connection = oledbconnection
				oledbcommand2.Connection.Open()

				strSQL = "DELETE FROM tblTimeOff WHERE DI = " & DataGrid1.Item(DataGrid1.CurrentRowIndex, 0)

				oledbcommand2.CommandText = strSQL
				Try
					oledbcommand2.ExecuteNonQuery()
				Catch ex As OleDbException
					MsgBox(ex.Message)
				End Try
				oledbcommand2.Connection.Close()

				data_adapter2 = New OleDbDataAdapter(SELECT_STRING, CONNECT_STRING)

				' Map Table to Employees.
				data_adapter2.TableMappings.Add("Table", "TimeOff")

				' Fill the DataSet.
				TO_DataSet = New DataSet
				data_adapter2.Fill(TO_DataSet)

				' Bind the DataGrid control to the Employees DataTable.
				DataGrid1.SetDataBinding(TO_DataSet, "TimeOff")
			End If

			DataGrid1.Refresh()

		Catch bigEx As Exception
			MsgBox("There is no data to delete.", MsgBoxStyle.Exclamation, "No Data")
		End Try
	End Sub
End Class

AnswerRe: Duplicate code - Unhandlable error Pin
Jon_Boy29-Jan-09 5:05
Jon_Boy29-Jan-09 5:05 
GeneralRe: Duplicate code - Unhandlable error Pin
Phantom71529-Jan-09 5:23
Phantom71529-Jan-09 5:23 
QuestionMS Access Database Pin
solomondevapaul12328-Jan-09 23:38
solomondevapaul12328-Jan-09 23:38 
AnswerUse linked tables Pin
David Mujica29-Jan-09 4:37
David Mujica29-Jan-09 4:37 
QuestionFile Attribute / Owner of file Pin
pedefetoll28-Jan-09 23:33
pedefetoll28-Jan-09 23:33 
AnswerRe: File Attribute / Owner of file Pin
Nanda_MR29-Jan-09 1:37
Nanda_MR29-Jan-09 1:37 
GeneralRe: File Attribute / Owner of file Pin
pedefetoll29-Jan-09 2:19
pedefetoll29-Jan-09 2:19 
AnswerRe: File Attribute / Owner of file Pin
dan!sh 29-Jan-09 3:51
professional dan!sh 29-Jan-09 3:51 
QuestionHow to schudule a click of button(VB .Net) in windows scheduler? Pin
Ramki Sankaran28-Jan-09 23:22
Ramki Sankaran28-Jan-09 23:22 
AnswerRe: How to schudule a click of button(VB .Net) in windows scheduler? Pin
Ashfield29-Jan-09 1:19
Ashfield29-Jan-09 1:19 
AnswerRe: How to schudule a click of button(VB .Net) in windows scheduler? Pin
Dave Kreskowiak29-Jan-09 3:28
mveDave Kreskowiak29-Jan-09 3:28 
GeneralRe: How to schudule a click of button(VB .Net) in windows scheduler? Pin
Jon_Boy29-Jan-09 3:37
Jon_Boy29-Jan-09 3:37 
QuestionLog On screen in VB.Net Pin
vijay248228-Jan-09 22:45
vijay248228-Jan-09 22:45 
AnswerRe: Log On screen in VB.Net Pin
Eddy Vluggen29-Jan-09 0:43
professionalEddy Vluggen29-Jan-09 0:43 
GeneralRe: Log On screen in VB.Net Pin
vijay248229-Jan-09 1:17
vijay248229-Jan-09 1:17 
GeneralRe: Log On screen in VB.Net Pin
Eddy Vluggen29-Jan-09 1:52
professionalEddy Vluggen29-Jan-09 1:52 
AnswerRe: Log On screen in VB.Net Pin
Ashfield29-Jan-09 1:22
Ashfield29-Jan-09 1:22 

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.