الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

اريد طريقة ربط قواد البياناتAccess في ال ASP.NET

مغلق
بدأه علي الحربي في 20 يونيو 2002 · 9 رد · 858 مشاهدة · في منتدى تصميم صفحات الويب
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

الي محترفي ال ASP.NEt

اود معرفة طريقة ربط قواعد البيانات Access مع المتصفح

واذا ما كلفت عليكم اريد مثال عمل لكي استفيد ويستفيد غيري

ومشكورين على المساعدة مقدماً

#2

Hello Brother,

When you are working with Access Database, you need to use the OleDb objects like:

OleDbConnection,OleDbCommand,OleDbDataReader,OleDbDataAdapter.

You can connect to Microsoft Access using two methods.you either use the Jet Driver,or ODBC driver.I will show you how to use the JET driver in the following code:

string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:students.mdb;";

   OleDbConnection myConnection = new OleDbConnection(myConnectionString);
   string myQuery = "select StudentID, StudentName from Students";  
 OleDbCommand myCommand = new OleDbCommand(myQuery);
   myCommand.Connection = myConnection;
   myConnection.Open();

OleDbDataReader dr = myCommand.ExecuteReader();

while(dr.Read()) //this is like 'WHILE NOT rs.EOF' in ASP
'it means go through the resultset until the end
{
'write the values to the client browser
Response.Write(dr.GetInt32(0) + ", " + dr.GetString(1));


}

we used GetInt32(0) becuase the first field in our query is an

integer which is StudentID,the second is string 'StudentName' so we used GetString(1).This is a zero-based index.The first field index is 0,the second is 1 and so on.....

Tahiyati

Madani

#3

مشكور madani

ولكن ماهي الطريقة لربط جدولين بينهما علاقة في نفس الوقت

مثال : إذا كان عندي جدولين الأول يحتوي على موضوعات والثاني يحتوي على مقالات أو أخبار متعلقة بهذة الموضوعات

فماهي الطريقة لطيع الموضوعات من جدول الموضوعات وطبع تحت كل موضوع المقالات المتعلقة به من جدول المقالات

أنا حاولت أسويها عن طريق ال DataSet ولكنها لم أعرف كيف تنفيذها بالضبط

الرجاء ممن يعرف أن يكتب مثالا كاملا لأني تعبت من إسبوع وأنا أدور في النت عن حل لهذة المشكلة

#4

Hello AlMomaiaz,

In this case you would use DataSet and store two tables inside it then you use the RowFilter property to filter the second dataview

Example:

First Table 'Subjects' which is the parent table

SubjectID

SubjectTitle

Second Table 'Articles' which is the child table

ArticleID

ArticleTitle

SubjectID

SubjectID in Articles table is a foreign key to link it with the Subjects table

 string myQuery = "Select*from Subjects";
			OleDbDataAdapter da = new OleDbDataAdapter(myQuery,OleDbConnection1);
			DataSet ds = new DataSet();
			da.Fill(ds,"Subjects");
			da.SelectCommand = new OleDbCommand("select*from Articles",OleDbConnection1);
			da.Fill(ds,"Articles");
			DataView Subjects = ds.Tables["Subjects"].DefaultView;
                        DataView Articles = ds.Tables["Articles"].DefaultView;

			for(int i=0;i			{
				Response.Write("this is the Subject Title " + Subjects["SubjectTitle"] + "
");
                                Response.Write("and these are the articles 
");
				Articles.RowFilter  = "SubjectID=" + Subjects["SubjectID"];
				for(int j=0;j				{
					Response.Write( Articles[j]["ArticleTitle"] + "
");

				}
			}

	}

If you are familiar with ADO you will find that RowFilter property is similar to the Filter property in ASP.

Tahiyati

Madani

#5

وهذا نفس الكود بعد ماحست فيه وخليته بال VB بدل ال C#

للفائدة الكود التالي شغال عندي وماعليك الا تغيير إسم قاعدة البيانات والجداول إن لزم الأمر

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%

      Dim cnNorthwind As OleDbConnection

     con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("database.mdb"))
     con.Open()


    Dim da As OleDbDataAdapter = new OleDbDataAdapter("Select * from Subjects",con)
   Dim  ds As DataSet = New DataSet()
   da.Fill(ds,"Subjects")
   da.SelectCommand = new OleDbCommand("select * from Articles",ccon)
   da.Fill(ds,"Articles")

	Dim Subjects As DataView
	Dim Articles As DataView

	Subjects = ds.Tables("Subjects").DefaultView
                  Articles = ds.Tables("Articles").DefaultView

Dim i, j As Integer

For i = 0 to Subjects.Count-1

Response.Write("
Subjects  " & Subjects(i)("SubjectTitle"))
Response.Write("
")

Articles.RowFilter  = "SubjectID=" & Subjects(i)("SubjectID")

For j = 0 to Articles.Count-1
Response.Write(Articles(j)("ArticleTitle"))
Response.Write("
")
Next


Next
%>
#6

(yess) (yess) (yess) (yess) (yess) (yess)

That's really excelent from you.

I hope that the code will be helpful .

Just one thing .With OleDbDataAdapter and SqlDataAdapter you do need to call the open() method to open the connection,it is opened by the DataAdapter itself

Tahiyati

Madani

#7

شكرا لك .....(f)... (f)... (f) ...... والله إنك حلت مشكلة كانت معقدتني و مالقيت لها حل قبل كذا :) :)

بس ما فيه كتاب أو موقع مزبوط يشرح كل الأمور هذي بالترتيب لأني تعبت في المواقع كلها ملخبطة وفيها معلومات كثيرة لكن صعب تستفيد منها لأنها غير مرتبة

#8

Hello Momaiaz,

The best way to find solutions to your problems is to search the net.For example if you searched yahoo using the keyword 'filter ado.net' the first result is this document:

http://samples.gotdotnet.com/quickstart/ho...FilterData.aspx

this document is actually part of the .NET framework and is already installed on your computer, all you need to do is to activate it.

Another way is to search the knowledge base from microsoft

http://support.microsoft.com/search

One important thing is the keyword you use to look for something.If you are looking for information on how to filter data in ASP.NET , it will be useless to type 'how to filter data in asp.net'.Instead you use just few words like 'filter ado.net' so you will get more results.

Tahiyati

Madani

#9

شكرا أستاد مدين أو :D :D مدني على الكود و الله إنه اكثر من رائع حل لي الف مشكله

فراس

قم بزيارة موقعنا الخاص C# Lover ... الموقع الخاص بمحبي لغة الـ #C العرب

http://arab.csharplover.com

#10

والان وقد تم شرح الطريقتان بالـ #C و الـ VB.NET

ممكن شرح تفضيلي لخطوات الكود نفسة مثلاً :

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
ما تفسير هذا الكود مثلاً

او

string myQuery = "Select*from Subjects";
OleDbDataAdapter da = new OleDbDataAdapter(myQuery,OleDbConnection1);

واذا أمكن ارفاق مثلاً على هذا المثال حتى لو كان بسيطاً جداً

شبكة

هذا الموضوع مغلق.

مواضيع مشابهة