VB.NET danna kattiya poddak annako.

Kasun k

Well-known member
  • Mar 11, 2009
    10,357
    492
    83
    United States
    Machan mage podi program akak thiyenawa. VB.NET 2008 (.NET Framework 3.5) walin karapu akak. oke machan dan ACCESS DB akak thiyene. meke setup aka hadala framework akath akkane ban denna ona neda.... Seup aka hadaddi Connection string aka kohmada wenas karanna ona???????? nikanma setup aka haduwoth Access table akath ahuwelada hadenne ???? poddak kiyannako...
     

    Core

    Member
    Jan 23, 2010
    3,120
    195
    0
    Milky Way/Local Cluster/Local Sol/Earth
    I can see you don't have a basic idea how DataBases work,first of all I can give you an advice honesty understand the theory then do the practicals.

    there are lot of ways you can connect with a database the easiest way is
    through a DataSet. and using a DataAdapter

    Dim _dataSet as new DataSet()
    Dim _dataAdapter as new System.Data.OleDbDataAdapter()
    Dim _con as new System.Data.OleDbConnection()

    Dim _commandString as String = "SELECT * From tableName";
    'remember if you want to get data from specific column then append
    'WHERE columnName=data (mostly the key) the it will return only that row

    Dim _com as new System.Data.OleDbCommand(_commandString ,_con);

    then made the connection string
    _con.ConnectionString = "in here you should give the connection string"
    it may depend on which version use

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB Database Password=MyDbPassword;

    the OLEDB 12 is the provider which handle the 2007 version of Access DataBases
    so it may be changed if that's 2003 or older

    if you want to change the command text later use
    _com.SelectCommand.CommandTet = "your command goes here"

    __dataAdapter.Fill(_dataSet,"Table\'s name of the dataSet);

    now you have made the connection and prepare everything now just open the connection
    _con.Open() 'then it will fill the DataSet from DataBase where you can manipulate your data while in the program.

    //now use your commands to work with DataSet
    //it uses
    Dim _row as DataRow = _dataSet.Tables["tablesName"].Rows[0]
    which will return the row number 0 in the tablesName table in the DataSet

    if you want to finally update the DataBase use

    CommandBuilder namespace

    but remember if you use
    _dataAdapter.Update(_dataSet,"the table where data in the dataset)
    you gotta use CommandBuilder as well.

    finally close and dispose everything
    _dataSet.Dispose()
    _dataAdapater.Dispose()
    _con.Close()
    _con.Dispose()
     
    Last edited:

    Core

    Member
    Jan 23, 2010
    3,120
    195
    0
    Milky Way/Local Cluster/Local Sol/Earth
    then change here
    Data Source=C:\myFolder\myAccess2007file.accdb

    and Use the Current Directory Property
    Dim _string as String = My.Computer.FileSystem.CurrentDirectory;

    Data Source=_string \myAccess2007file.accdb <- like this.

    it will return the current directory so you don't need to change the path always