PDA

View Full Version : کار با adodb در vb.net



vahidhatefi
شنبه 30 آبان 1388, 14:28 عصر
طرح سوال

لطفا کار با این شی را به من بیاموزید
فوری
متشکرم

milad.biroonvand
چهارشنبه 04 آذر 1388, 17:13 عصر
از این استفاده کن


دستيابی به بانک اطلاعاتی Access با استفاده از VB.NET
در اين مقاله قصد داريم به نحوه بازيابی و نمايش اطلاعات موجود در يک بانک اطلاعاتی Access اشاره نمائيم . هدف از مقاله فوق ، پرداختن به تمامی رويکردهای موجود در اين زمينه نبوده و صرفا" به معرفی يکی از گزينه های موجود در اين زمينه اشاره خواهد شد. در اين راستا از تکنولوژی های ASP.NET ، ADO.NET و VB.NET استفاده خواهد شد . از کلاس های OleDbConnection ، OleDbCommand و OleDbDataReader مربوط به ADO.NET بمنظور انجام عمليات لازم در ارتباط با بانک اطلاعاتی ، از ASP.NET بمنظور ايجاد فرم وب و ارائه داده با استفاده از کنترل سرويس دهنده Table و از زبان VB.NET بمنظور نوشتن دستورالعمل های مورد نظر استفاده می گردد .
در ابتدا لازم است با سه کلاس ADO.NET که در ادامه از آنان استفاده خواهد شد ، بيشتر آشنا شويم :
•کلاس OleDbConnection . شی فوق ، يک اتصال منحصر بفرد با يک منبع داده را ايجاد می نمايد. در رابطه با يک بانک اطلاعاتی سرويس گيرنده / سرويس دهنده ، اين امر معادل يک اتصال شبکه به سرويس دهنده است . با توجه به قابليت های حمايت شده توسط native OLE DB Provider ، برخی از متدها و يا خصلت ها مربوط به شی OleDbConnection ممکن است در دسترس و قابل استفاده نباشد . زمانيکه نمونه ای از OleDbConnection ايجاد می گردد ، تمامی خصلت های مربوطه ، مقدار اوليه خود را دارا خواهند بود . پس از اتمام عمليات موردنظر در ارتباط با بانک اطلاعاتی ، می بايست با فراخوانی Close و يا Dispose اقدام به غير فعال نمودن اتصال ايجاد شده با بانک اطلاعاتی مربوطه نمود.
•کلاس OleDbCommand . يک عبارت SQL و يا Stored procedure را بمنظور اجراء در رابطه با يک منبع داده ارائه می نمايد. کلاس فوق از متدهای زير بمنظور اجرای دستورات در رابطه با يک منبع داده استفاده می نمايد.
ExecuteReader . متد فوق ، دستوراتی را اجراء می نمايد که خروجی آنان شامل سطرهائی خواهد بود.
ExecuteNonQuery . باعث اجرای دستوراتی نظير SQL INSERT,DELETE,UPDATE و SET خواهد شد .
ExecuteScalar . بازيابی صرفا" يک مقدار از يک بانک اطلاعاتی
• کلاس OleDbDataReader . متد فوق ، امکان خواندن سطرهائی از داده موجود در يک منبع داده را فراهم می نمايد( فقط بسمت جلو) . بمنظور ايجاد يک OleDbDataReader ، می بايست متد ExecuteReader مربوط به شی OleDbCommand فراخوانده شود. ماداميکه OleDbDataReader در حال استفاده است (اتصال مرتبط OleDbConnection ) ، عمليات ديگری را در ارتباط با OleDbConnection نمی توان انجام داد .
امکانات مورد نياز
برای دنبال نمودن اين مقاله و اجرای نمونه مثالی که در ادامه بررسی می گردد ، به امکانات زير نياز خواهد بود :
•نصب يکی از نسخه های ويندوز 2000 و يا نسخه ويندوز 2003
•نصب IIS
• نصب فريمورک دات نت نسخه 1.0 ,يا نسخه 1.1
•يک بانک اطلاعاتی نمونه اکسس نظير Northwind
ايجاد يک برنامه وب ASP.NET با استفاده از VB.NET
بمنظور ايجاد يک برنامه وب ASP.NET با استفاده از VB.NET مراحل زير را دنبال می نمائيم :
• اجرای برنامه ويژوال استوديو دات نت
•از طريق منوی File ، گزينه New و در ادامه Project را انتخاب نمائيد .
• در جعبه محاوره ای New Project ، در بخش Project Types گزينه Visual Bacic Projects را انتخاب ( کليک ) و در ادامه ASP.NET Web Application را انتخاب نمائيد .
• در فيلد Location ، بجای نام پيش فرض #WebApplication ، نام TestAccessDB را انتخاب نمائيد . در صورتيکه از يک سرويس دهنده محلی استفاده میگردد ، می توان نام سرويس دهنده را http://localhost (http://localhost/) در نظر گرفت . بدين ترتيب در فيلد Location ، آدرس مربوطه بصورت زير نشان داده خواهد شد : http://localhost/TestAccessDB

ايجاد يک فرم وب نمونه
در نمونه کد نوشته شده از کنترل سرويس دهنده Table مربوط به ASP.NET استفاده شده که بصورت پويا يک نمايش ساده از داده بازيابی شده را نشان خواهد داد. ASP.NET ، مجموعه متنوعی از کنترل های انعطاف پذير را ارائه که می توان از آنان با توجه به رويکردهای متفاوت در رابطه با نمايش داده استفاده نمود. بمنظور ايجاد يک فرم وب در پروژه ايجاد شده در مرحله قبل ، مراحل زير را دنبال می نمائيم :
• اضافه نمودن يک فرم جديد با نام DataSample.aspx به برنامه وب ASP.NET در ويژوال استوديو دات نت . بمنظور انجام خواسته فوق ، دو مرحله زير را دنبال می نمائيم :
مرحله يک : در Solution Explorer ، بر روی گره Project کليک سمت راست نموده و گزينه Add و در ادامه گزينه Add Web Form انتخاب گردد.
مرحله دو : درفيلد Name ، نام DataSample.aspx را درج و در ادامه گزينه Open انتخاب گردد .
• از طريق Toolbox مربوط به Web Forms Tab ، يک Table ASP.NET Server Control را انتخاب ( Drag ) و بر روی صفحه aspx . مستقر نمائيد ( در حالت Desgin view ) .
• در Properties نام ID را به DisplayTable تغيير دهيد .
•در Solution Explorer ، بر روی صفحه aspx . ، کليک سمت راست نموده و گزينه View Code را انتخاب نمائيد .
•مرجع namespace زير را در بالاترين قسمت فايل کلاس code-behind وارد نمائيد .

Imports System.Data.OleDb
•کد زير را در ارتباط با رويداد Page_load در نظر می گيريم :

Page_Load Event handler
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
استفاده از يک متغير رشته ای بمنظور ذخيره سازی Connectionstring'

Dim connectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=C:\MyDB\NWIND.MDB"
ايجاد يک شی OleDbConnection و ارسال مقدار متغير ConnectionString '

Dim cn As OleDbConnection = New OleDbConnection(connectString)
فعال نمودن Connection'
cn.Open()
استفاده از يک متغير بمنظور ذخيره عبارت SQL'

Dim selectString As String = "SELECT CustomerID, ContactName, Phone FROM Customers"
ايجاد يک شی OledbCommand'
در اين خط متغير عبارت SQL و شی OleDbConnection ، ارسال می گردد '
Dim cmd As OleDbCommand = New OleDbCommand(selectString, cn)
ارسال CommandText به Connection و ايجاد يک OleDbDataReader '
OleDbDataReader از نوع " فقط بسمت جلو " خواهد بود'
Dim reader As OleDbDataReader = cmd.ExecuteReader()
تنظيم عرض جدول '
DisplayTable.Width = Unit.Percentage(90.0)
ايجاد يک سطر جديد برای اضافه نمودن عنوان جدول'
Dim tableHeading As TableRow = New TableRow()
ايجاد و اضافه نمودن سلول های شامل ستون Customer ID '
Dim customerIDHeading As TableHeaderCell = New TableHeaderCell()
customerIDHeading.Text = "Customer ID"
customerIDHeading.HorizontalAlign = HorizontalAlign.Left
tableHeading.Cells.Add(customerIDHeading)
ايجاد و اضافه نمودن سلول های شامل ستون Contact Name '
Dim contactNameHeading As TableHeaderCell = New TableHeaderCell()
contactNameHeading.Text = "Contact Name"
contactNameHeading.HorizontalAlign = HorizontalAlign.Left
tableHeading.Cells.Add(contactNameHeading)
ايجاد و اضافه نمودن سلول های شامل ستون Phone '
Dim phoneHeading As TableHeaderCell = New TableHeaderCell()
phoneHeading.Text = "Phone"
phoneHeading.HorizontalAlign = HorizontalAlign.Left
tableHeading.Cells.Add(phoneHeading)
DisplayTable.Rows.Add(tableHeading)
تکرار در بين داده انتخابی نتايج و افزودن داده برای هر يک از ستون های مورد نظر در جدول '
While(reader.Read())
Dim detailsRow As TableRow = New TableRow()
Dim customerIDCell As TableCell = New TableCell()
customerIDCell.Text = reader("CustomerID").ToString()
detailsRow.Cells.Add(customerIDCell)
Dim contactNameCell As TableCell = New TableCell()
contactNameCell.Text = reader("ContactName").ToString()
detailsRow.Cells.Add(contactNameCell)
Dim phoneCell As TableCell = New TableCell()
phoneCell.Text = reader("Phone").ToString()
detailsRow.Cells.Add(phoneCell)
DisplayTable.Rows.Add(detailsRow)
End While
بستن Connection'
reader.Close()
cn.Close()
End Sub


• مقدار متغير ConnectString در ابتدای کد نوشته شده فوق را تغيير و آن را به محلی که بانک اطلاعاتی موجود است ، اشاره دهيد .
• از طريق منوی File ، گزينه Save All را انتخاب تا فرم وب و ساير فايل های مرتبط با پروژه ، ذخيره گردد .
•از طريق منوی Build ، گزينه Build Solution را بمنظور ايجاد پروژه ، فعال نمائيد.
•در Solution Explorer ، بر روی DataSample.aspx کليک سمت راست و در ادامه گزينه View in Browser را انتخاب نمائيد . در ادامه صفحه در مرورگر نمايش و شامل داده موجود در بانک اطلاعاتی مربوطه است .

اشکالات و خطاهای احتمالی
درزمان اجراء ، ممکن است با خطائی مانند زير مواجه شويم :


The Microsoft Jet database engine cannot open the file 'C:\MyDB\NWIND.MDB'.
It is already opened exclusively by another user, or you need permission to view its data.


•خطای فوق ، اغلب بدليل عدم داشتن مجوز لازم بمنظور دستيابی به فايل ( فايل بانک اطلاعاتی با انشعاب mdb . ) می باشد . بصورت پيش فرض ، ASP.NET تحت ASPNET account در فريمورک دات نت نسخه يک و يا NetworkService در فريمورک دات نت نسخه 1،1 اجراء می گردد.در اين رابطه لازم است تغييرات لازم در رابطه با مجوز دستيابی به فايل mdb . و فولدری که شامل فايل است ، اعمال گردد .
•از نصب عناصر مورد نياز Microsoft Jet database بر روی سيستم ، مطمئن گرديد. در صورتيکه MDAC 2.6 نصب شده باشد ( Microsoft Data Access Components 2.6) ، عناصر Jet را شامل نمی گردد . در چنين مواردی می بايست آخرين نسخه Jet 4.0 Service Pack ، بر روی سيستم نصب گردد.

منبع
http://www.iritn.com

keyvannn
پنج شنبه 05 آذر 1388, 00:00 صبح
سلام، یه سمپل در مورد ارتباط vb با پایگاه دادهOracle8i میخواستم .اگه کمکم کنید خیلی ممنون میشم.

milad.biroonvand
پنج شنبه 05 آذر 1388, 11:45 صبح
چیزهایی که باید تعریف کنی


Dim con As New OracleConnection(_conString)
Dim cmd As New OracleCommand(query, con)
cmd.CommandType = CommandType.Text
con.Open()
Dim trans As OracleTransaction = con.BeginTransaction()
Dim trans As OracleTransaction = con.BeginTransaction()
Try

cmd.ExecuteNonQuery()
trans.Commit()

Catch e As Exception

trans.Rollback()

End Tryبه این سایت ها مراجعه کن ، آموزش همراه با تصویر

http://www.oracle.com/technology/pub/articles/cook_dotnet.html

http://www.startvbdotnet.com/ado/oracle.aspx


اینهم یک مقاله لاتین
General:
The following code will help you to create a table called "emp" in oracle database with three fields namely id, name, photo. The field photo is a blob field for which you are going to insert an image as the value using the code. The image size may be anything even in GB as the blob field in oracle can store upto 4GB of size.
Code to create a table in oracle database:
public void oracleconnection()

{

try

{

//use your own userid,password and datasorce

connstr="User Id="userid ";Password="password" ;Data Source="datasource ";";

conn=new OracleConnection(connstr);

conn.Open();

OracleCommand cmnd=conn.CreateCommand();

cmnd.CommandText="CREATE TABLE emp(id INTEGER,name VARCHAR2(50),photo BLOB)";

cmnd.ExecuteNonQuery();

}

catch(Exception e)

{

MessageBox.Show(e.Message);

}

}
Working of the code:
Using the fileopendialog() you can give the path of the .jpg file in your system. This file is then converted as a bitmap image and stored in a picture box as its image. To insert an image into the blob field, you have to use a filestream object. Using filestream you have to read() the imagefile and store it as byte[] array as in C#‎‎.Net. Then you have to insert the byte array to the blob field as an Oracle parameter which is of parameter type Blob and its value as the byte[] array specified above, using normal sql query used for insertion.
The same you have to do while retrieving the image. You have to specify the name to store the retrieved image as "image.jpg" (which is stored in the bin folder of your project). For this you have to select all the rows in the table and select the column of teh image ie. The blob field with the datarow and the datacolumn properties where the image is stored as blob in the database. Using the same filestream object write() the entire file upto its length and retrieve the same image in the picture box control.
USING THE CODE:
(1) For inserting the data into the blob field of the database
Note: This should be done after creating the table in oracle database as specified above in this article.
Open a project in C#‎‎ and name it as oracleblob. Now click add reference and in .Net category select "System.data.Oracleclient.dll". Then in your project add before the namespace using system.data.oracleclient.
Now in the form1 add two textboxes, two labels, three buttons and a picturebox and name them as follows:


textbox:txtid,txtname
label:lblid,lblempname
buttons:btnbrowse,btnsave,btnclose
picturebox:pctimg

Declare these variables as global:
OracleConnection conn;
string connstr; When the user gives the id and name in the textboxes and update the picturebox's image by specifying the path of image using Browse button, the picture is loaded in the picturebox. When he clicks the save button then these details are inserted as a row in the table. After inserting he can close the application using close button.(see picture of the form form1.jpg).
The code for the browse button is as follows:
This will open a dialogbox wherein you can select the image file's path.
private void btnbrowse_Click(object sender, System.EventArgs e)

{

try

{

FileDialog fldlg=new OpenFileDialog();

//specify your own initial directory

fldlg.InitialDirectory=@":D\";

//this will allow onlt those file extensions to be added

fldlg.Filter="Image File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif";

if(fldlg.ShowDialog()==DialogResult.OK)

{

imagename=fldlg.FileName;

Bitmap newimg=new Bitmap(imagename);

pctimg.SizeMode=PictureBoxSizeMode.StretchImage;

pctimg.Image=(Image)newimg;

}

fldlg=null;

}

catch(System.ArgumentException ae)

{

imagename=" ";

MessageBox.Show(ae.Message.ToString());

}

catch(Exception ex)

{

MessageBox.Show(ex.Message.ToString());

}

}
The code for save button is as follows:

This code will add the details specified in textboxes namely the id, name and the image in picturebox to a row in the table created inoracle database. This code uses the function Updatedata() which is explained as follows:
private void updatedata()

{

//use filestream object to read the image.

//read to the full length of image to a byte array.

//add this byte as an oracle parameter and insert it into database.

try

{

//proceed only when the image has a valid path

if(imagename!="")

{

FileStream fls;

fls=new FileStream(@imagename,FileMode.Open,FileAccess.Rea d);

//a byte array to read the image

byte[] blob=new byte[fls.Length];

fls.Read(blob,0,System.Convert.ToInt32(fls.Length) );

fls.Close();

//open the database using odp.net and insert the data

connstr="User Id="userid";Password="password";Data Source="datasource";";

conn=new OracleConnection(connstr);

conn.Open();

OracleCommand cmnd;

string query;

query="insert into emp(id,name,photo) values(" + txtid.Text + "," + "'" + txtname.Text + "'," + " :BlobParameter )";

//insert the byte as oracle parameter of type blob

OracleParameter blobParameter = new OracleParameter();

blobParameter.OracleType = OracleType.Blob;

blobParameter.ParameterName = "BlobParameter";

blobParameter.Value = blob;

cmnd=new OracleCommand(query,conn);

cmnd.Parameters.Add(blobParameter);

cmnd.ExecuteNonQuery();

MessageBox.Show("added to blob field");

cmnd.Dispose();

conn.Close();

conn.Dispose();

}

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}
Code in the save button:
private void btnclose_Click(object sender, System.EventArgs e)
{
this.Close();
} Note: Add a few rows in the table using the above mentioned procedure so that it will be helpful in retreiving the blob field.
(2) For retreiving the image from the blob field of the oracle database
Open a form to the same project and name it as frmread.cs. Then in your project add using system.data.oracleclient.Now in the form1 add one combobox, one label, two buttons and a picturebox and Name them as follows:


combobox:cmbempname (*make its dropdown property as dropdownlist)
label:lblname
buttons:btnshow,btnclose
picturebox:pctimg

When the form loads the name is added in the combobox, the user has to select a name, and when he clicks the show button, the corresponding image in the blob field is retreived and added to the picturebox. See the form in the picture frmread.jpg.
Declare these variables as global in the form:
OracleConnection conn;
OracleDataAdapter empadap;
DataSet dset;
string connstr; Code for the Show button:
There is a function named connection() which performs the work of adding all the names ito combobox after getting them from the database using oracledataadapter(). This should be used in the form's Load event,so that it helps user to select one of the names which is in the table added using the previous form.
private void Frmread_Load(object sender, System.EventArgs e)

{

Connection();

}

private void Connection()

{

//connect to the database and table

//selecting all the columns

//adding the name column alone to the combobox

try

{

connstr="User Id=scott;Password=tiger;Data Source=star;";

conn=new OracleConnection(connstr);

conn.Open();

empadap=new OracleDataAdapter();

empadap.SelectCommand=new OracleCommand("SELECT * FROM emp",conn);

dset=new DataSet("dset");

empadap.Fill(dset);

DataTable dtable;

dtable=dset.Tables[0];

cmbempname.Items.Clear();

foreach(DataRow drow in dtable.Rows)

{

cmbempname.Items.Add(drow[1].ToString());

cmbempname.SelectedIndex=0;

}

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}

Now the code inside the show button is as follows:

private void btnshow_Click(object sender, System.EventArgs e)

{

DataTable dataTable = dset.Tables[0];

//if there is an already an image in picturebox, then delete it

if(pctimg.Image != null)

{

pctimg.Image.Dispose();

}

//using filestream object write the column as bytes and store it as an image

FileStream FS = new FileStream("image.jpg", FileMode.Create);

foreach(DataRow dataRow in dataTable.Rows)

{

if(dataRow[1].ToString() == cmbempname.SelectedItem.ToString())

{

byte[] blob = (byte[])dataRow[2];

FS.Write(blob,0,blob.Length);

FS.Close();

FS = null;

pctimg.Image = Image.FromFile("image.jpg");

pctimg.SizeMode = PictureBoxSizeMode.StretchImage;

pctimg.Refresh();

}

}

}

Code in the close button:

private void btnclose_Click(object sender, System.EventArgs e)

{

conn.Close();

this.Close();

}

Note: The image is retreived from the blob field and added to the picturebox control and also is stored as "image.jpg" in the bin folder of your application.
Summary:
I hope this article will clear your doubts regarding how to insert an image in a blob field of an oracle database and then how to retreive the image stored in a blob field.
private void btnsave_Click(object sender, System.EventArgs e)
{ this.updatedata();
]

milad.biroonvand
پنج شنبه 05 آذر 1388, 11:53 صبح
اینهم یک نمونه کد :


Using OleDb Provider
The Objects of the OleDb provider with which we work are:
The OleDbConnection Class
The OleDbConnection class represents a connection to OleDb data source. OleDb connections are used to connect to most databases.
The OleDbCommand Class
The OleDbCommand class represents a SQL statement or stored procedure that is executed in a database by an OLEDB provider.
The OleDbDataAdapter Class
The OleDbDataAdapter class acts as a middleman between the datasets and OleDb data source. We use the Select, Insert, Delete and Update commands for loading and updating the data.
The OleDbDataReader Class
The OleDbDataReader class creates a data reader for use with an OleDb data provider. It is used to read a row of data from the database. The data is read as forward-only stream which means that data is read sequentially, one row after another not allowing you to choose a row you want or going backwards.
Sample Code
We will work with the sample Emp table in Oracle.
Retrieving Records
Imports System.Data.OleDB
Public Class Form1 Inherits System.Windows.Forms.Form
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dr As New OleDbDataReader()
'declaration
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)_
Handles MyBase.Load
myConnection = New OleDbConnection_
("Provider=MSDAORA.1;UserID=scott;password=tiger; database=ora")
'MSDORA is the provider when working with Oracle
Try
myConnection.Open()
'opening the connection
myCommand = New OleDbCommand("Select * from emp", myConnection)
'executing the command and assigning it to connection
dr = myCommand.ExecuteReader()
While dr.Read()
'reading from the datareader
MessageBox.Show("EmpNo" & dr(0))
MessageBox.Show("EName" & dr(1))
MessageBox.Show("Job" & dr(2))
MessageBox.Show("Mgr" & dr(3))
MessageBox.Show("HireDate" & dr(4))
'displaying data from the table
End While
dr.Close()
myConnection.Close()
Catch e As Exception
End Try
End Sub
End Class
The above code displays first 5 columns from the Emp table in Oracle.
Inserting Records
Drag a Button from the toolbox onto the Form. When this Button is clicked the values specified in code will be inserted into the Emp table.
Imports System.Data.OleDb
Public Class Form2 Inherits System.Windows.Forms.Form
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim ra as Integer
'integer holds the number of records inserted
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
myConnection = New OleDbConnection(""Provider=MSDAORA.1;User_ ID=scott;password=tiger;database=ora")
Try
myConnection.Open()
myCommand = New OleDbCommand("Insert into emp values 12,'Ben','Salesman',300,_
12-10-2001,3000,500,10 ", myConnection)
'emp table has 8 columns. You can work only with the columns you want
ra=myCommand.ExecuteNonQuery()
MessageBox.Show("Records Inserted" & ra)
myConnection.Close()
Catch
End Try
End Sub
End Class
Deleting Records
Drag a Button on a new form and paste the following code.
Imports System.Data.OleDb
Public Class Form3 Inherits System.Windows.Forms.Form
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim ra as Integer
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles Button1.Click
Try
myConnection = New OleDbConnection(""Provider=MSDAORA.1;User_ ID=scott;password=tiger;database=ora")
myConnection.Open()
myCommand = New OleDbCommand("Delete from emp where DeptNo=790220",_
myConnection)
ra=myCommand.ExecuteNonQuery()
MessageBox.Show("Records Deleted" & ra)
myConnection.Close()
Catch
End Try
End Sub
End Class
Updating Records
Drag a Button on a new form and paste the following code.
Imports System.Data.OleDb
Public Class Form4 Inherits System.Windows.Forms.Form
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim ra as Integer
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles Button1.Click
Try
myConnection = New OleDbConnection(""Provider=MSDAORA.1;User_ ID=scott;password=tiger;database=ora")
myConnection.Open()
myCommand = New OleDbCommand("Update emp Set DeptNo=65 where DeptNo=793410",_ myConnection)
ra=myCommand.ExecuteNonQuery()
MessageBox.Show("Records Updated" & ra)
myConnection.Close()
Catch
End Try
End Sub
End Class

Hossis
چهارشنبه 12 خرداد 1389, 07:56 صبح
ولی من فکر می کنم پاسخ سؤال کننده داده نشده چون ایشان در مورد Adodb سؤال کرده بودند نه OLEDB و ارتباط مزبور چنین است
Dim DB As new ADODB.Connection
Dim RS as new recordset
...

brilliantprogrammer
جمعه 14 خرداد 1389, 13:16 عصر
از adodb براي کار با انواع پايگاه هاي داده استفاده مي شه . براي اتصال بايد ابتدا يک کانکشن بسازي با استفاده از کانکشن به پايگاه داده متصل مي شي. بعد با يک رکورد ست يا يک کامند به جدول يا کوري خاص در پايگاه داده متصل مي شي. شي adodb هزارو يک کلاس رو تو خودش جا داده و هر کلاس هزارو يک متد و رويدادو .... دارن. يک قطرش رو اينجا مي نويسم.
Dim NameConnection As New ADODB.Connection()
Dim RecordsetName As New ADODB.Recordset
اين کدها معمولا بيرون از رويدادها نوشته ميشه و معمولا براي باز کردن اين دو شي از رويداد لود استفاده ميشه
NameConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0;Data source = "D/data/data.mdb)
RecordsetName.Open("Select * From TableName",ConnectionName,ForwardOnly,ReadOnly)
حالا شما به جدول مورد نظر متصل هستيد و براي مشاهده اطلاعات جدول مي توانيد از خصوصيات فيلد از کلاس رکوردست استفاده کنيد.
RecordsetName.Filds("ColumnName").Value

ashkan209
جمعه 14 خرداد 1389, 16:27 عصر
طرح سوال

لطفا کار با این شی را به من بیاموزید
فوری
متشکرم

حالا چرا adodb ، اونم توی دات نت
بهتر نیست برید دنبال Ado.net به اون قدرتمندی و زیبایی:لبخندساده:

kashir
چهارشنبه 03 شهریور 1389, 11:28 صبح
یکی میتونه نحوه ی ارتباط vb.net با accsess2007 رو بهم آموزش بده؟؟؟؟؟چطوری میتونم گزارش گیری کنم؟