VB.NET/ADO.net easy as msaccess project

superbem

Member
Joined
May 17, 2007
Messages
22
Programming Experience
10+
Because I don't ever see a so much simple and powerfull data management as in msaccess, I want to make it simple to vb.net too. All without the wizards that come with visual basic 2005 since I'm using sharpdevelop vb.net.

I'm meaning the easy way of putting a simple sql in the datasource of form/report, and it binds all automatic. I'm trying to do a tool that makes this possible, but I don't know how to make the designs-time.

Here is the code, I'll thank some help.

PHP:
Option Strict Off 
Option Explicit Off

imports System.Data
Imports System.Data.OleDb

Public Module dSource
	Dim daManual(100)
	Dim dsManual =New DataSet
	Dim numt=0
	Public Sub dtsource(dest as object  ,con as String  ,strSQL as String )
		Try
			dim dcManual As New OleDb.OleDbConnection(con)
			numt+=1
			daManual(numt) = New OleDb.OleDbDataAdapter
			daManual(numt).SelectCommand = New OleDb.OleDbCommand(strSQL, dcManual)
			dim cbManual= New OleDb.OleDbCommandBuilder(daManual(numt))
			daManual(numt).Fill(dsManual, cstr(numt))
			dest.DataSource = dsManual.Tables(CStr(numt))
			
			'Im sure there is better way for autoupdate the db,other objects must be added here
			If dest.GetType().ToString ="System.Windows.Forms.DataGridView" Then
				AddHandler CType(dest,DataGridView).Validated, AddressOf dtValida
			End If
			If dest.GetType().ToString ="System.Windows.Forms.BindingSource" Then
				AddHandler CType(dest,BindingSource).CurrentChanged, AddressOf dtValida
			End If
			
		Catch ex As Exception
		End Try
	End Sub
	Public Sub savedataset()
		on error resume next
		Dim i
		If (dsManual.HasChanges) Then
			For i = 1 To numt
				daManual(i).Update(dsManual.Tables(CStr(i)))
			Next i
			dsManual.AcceptChanges()
		end if
	End Sub
	Sub dtValida (ByVal sender As System.Object, e As System.EventArgs)
		saveDataset
	End Sub
End Module

To bind to a datagridview for example just use:

PHP:
dtsource(dataGridView1,"Provider=Microsoft.Jet.OleDb.4.0;Data Source=sample.mdb;","select * from table")

I'm now trying to make possible a textbox to recognize a databind at design-time, but I don't know how, maybe turning this a class or something?
 

superbem

Member
Joined
May 17, 2007
Messages
22
Programming Experience
10+
build 2

PHP:
imports System.Data
Imports System.Data.OleDb
Imports System.Data.Common

Public Module dSource
	Public daManual(100)
	Public dsManual as DataSet =New DataSet
	Public numt=0
	Public bds(100) as BindingSource
	Public Sub dtsource(dest as object  ,con as String  ,strSQL as String )
		dim dcManual As New OleDb.OleDbConnection(con)
		numt+=1
		daManual(numt) = New OleDb.OleDbDataAdapter
		daManual(numt).SelectCommand = New OleDb.OleDbCommand(strSQL, dcManual)
		dim cbManual= New OleDb.OleDbCommandBuilder(daManual(numt))
		daManual(numt).Fill(dsManual, cstr(numt))
		bds(numt)=New BindingSource
		bds(numt).DataSource =dsManual.Tables(CStr(numt))
		dest.DataSource = bds(numt)
		addhandler dsManual.Tables(CStr(numt)).RowChanged, addressof dtValida
	End Sub
	Public Sub savedataset()
		'On Error Resume Next
		Try
			Dim i
			For i = 1 To numt
					bds(i).EndEdit()
			Next i
			If (dsManual.HasChanges) Then
			For i = 1 To numt
				daManual(i).Update(dsManual.Tables(CStr(i)))
			Next i
			dsManual.AcceptChanges()
			end if
		Catch ex As Exception
		end try
	End Sub
	Sub dtValida (ByVal sender As System.Object, e As DataRowChangeEventArgs )
		saveDataset
	End Sub
End Module

Some cleaning...

To bind to a textbox:

PHP:
 Dim bs As New BindingSource
 		dtsource(bs,"Provider=Microsoft.Jet.OleDb.4.0;Data Source=sample.mdb;","select * from table")
 		textbox1.DataBindings.Add("Text",bs,"theField")


And a formated textbox (Only the time for example)
PHP:
 Dim bs As New BindingSource
 		dtsource(bs,"Provider=Microsoft.Jet.OleDb.4.0;Data Source=sample.mdb;","select * from table")
 		textbox1.DataBindings.Add("Text",bs,"theField",1,0,0,"hh:mm")



Remember this is a autosave conection. I hate they don't already have a option if the programmer simply wants to autosave data.

Still don't know how to put this in design-time...

cheers
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
All without the wizards that come with visual basic 2005 since I'm using sharpdevelop vb.net.
I dont use #develop but basically, you seem to be asking how to get the amazing functionality fo the data wizards in vb.net IDE.

Er. How about using VB.NET IDE

I'm meaning the easy way of putting a simple sql in the datasource of form/report, and it binds all automatic.
Yeah, but it never is just that simple. If it were we would all still be using Access. If you want it simple, use Access.. .NET was intended for more complex things, and it doesnt necessarily follow that the simple things are simple

I'm trying to do a tool that makes this possible, but I don't know how to make the designs-time.
Erm.. If youre looking to re-invent the data wizards in VB.NET, I guess installing it and looking at what they do would be a good start! :)
 

alander

Well-known member
Joined
Jun 26, 2007
Messages
120
Location
Singapore
Programming Experience
5-10
So u are asking for tips for ur GUI for ur codeS?
 
Last edited:
Top Bottom