beginner#vb.net using ado.net

  • Thread starter Thread starter MUHAMAMD SALIM SHAHZAD
  • Start date Start date
M

MUHAMAMD SALIM SHAHZAD

dear respected sir,
i'm beginner in vb.net and ado.net enviornment...

i would like to work and learn business(database applicatiosn area),
please can any one help me solve this...

i wanted to make very simple windows forms,then by programming want to
create query, connection, datasets, dataadapter,databinding for using
oledb

but i am facing a lots problem in syntax i am stuck/dead

imports system.data
imports system.data.oledb

private sub form1_load(......some val,ref..etc)

dim cn as new oledb.oledbconnection("provider=microsoft.jet.oledb.4.0;date
source=c:\northwind.mdb")
cn.open
dim da as new dataadapter("select * from customers",cn)
dim ds as new datasets()
da.fill(ds,"cutomers")

textbox1.text = textbox1.databinding.add(ds,"companyname")

end sub

and i have some buttons add, edit, delete, update...

so i can not success above...can any one help me to tell in very
simple form and how to update actual datbase...in fact by using
dataset it is update modify data...using datagrids...but failure in
case of indvidual records on the forms...and plus only update at
datasets time...not actual when i close form and open again..then it
give me same no of old records...

please can any one give some guidence appreciated sir

urs obediently

shahzad
 
dear sir,

thanks a lots as u r like angel and teacher for me...

sir my problem, i want to do everything by programming...as by wizard
i sucees...but i could nt succes in add, edit delte records...any
single example will be enought to make me understand this all...

as it seems difficult, which is not ..as i am beginner in database
vb.net programming

so sir what i wanted to knew there is already i hve first, next, prev,
last buttons...and even update and load data is ther..but working on
dataset...but actual data did nt effect...

let us consuder i did all by wizard using da, ds, cn....but even
though dataset updates records but actual data did not

sir any samples examples of coding of access database will be
appreciated

thanks u very much

urs obedintly, shahzad
 
Muhamamd:

Imports System.Data
Imports System.Data.OleDb

Public Class SomeForm

Private cn as OledbCOnnection
Private da as OledbDataAdapter
Private cmdb as OleDbCommandBuilder
Private ds as DataSet

Then down in Form Load


cn = New OledbConnection("someConnectionString")
da = New OleDbDataAdapter("SELECT Blah from SomeTable", cn)

ds = New DataSet("SomeTableName")

da.Fill(ds)

cmdb = new OledbCommandBUilder(da)

Debug.WriteLine(cmdb.GetUpdateCommand.CommandText & " " &
cmdb.GetSelectCommand.CommandTexgt & " Whatever else you want to verify has
been generated")

Then assuming you had a DataGrid (dg)

dg.DataSource = ds.Tables(0)



On an update button or Grid Event that you want to signal update time

da.Update(ds)
ds.AcceptChanges()


If you had a Cancel button


ds.RejectChanges()

I think the Wizard is generating the code for you for update and insert
etc... but if you don't use it, you'll need to use a CommandBuilder
something like I have above, or write your own logic (which is sometimes
worth it, but CommandBuilders will often get you where you need to go)

If you need anything else, or have any questions, let me know.

Good Luck my friend,

Bill
 
Back
Top