0% found this document useful (0 votes)
196 views9 pages

C# Access Database Integration Code

This C# code defines methods for connecting an Access database to an application and performing CRUD operations on different tables in the database. It includes methods for adding student, attendance, and class data to tables, as well as listing data from tables and populating it in list views with alternating row colors. The methods open a connection to an Access database, build SQL queries with parameters, execute queries, and handle exceptions.

Uploaded by

Mubashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
196 views9 pages

C# Access Database Integration Code

This C# code defines methods for connecting an Access database to an application and performing CRUD operations on different tables in the database. It includes methods for adding student, attendance, and class data to tables, as well as listing data from tables and populating it in list views with alternating row colors. The methods open a connection to an Access database, build SQL queries with parameters, execute queries, and handle exceptions.

Uploaded by

Mubashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C# Code for Ms Access Database link with application

using System;

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

using [Link];

namespace [Link]

class AddtoDataBase

OleDbConnection con = new


OleDbConnection(@"Provider=[Link].12.0;Data
Source=.\[Link]");

public void AddStudent(StudentInfo add)

// StudentInfo add =new StudentInfo();


OleDbCommand cmd = new OleDbCommand();

[Link] = con;

[Link] = "INSERT INTO StudentInfo([RollNO],[StName], [StFname],


[DOB],[CNIC],[FCelNO], [Address],[ClassName], [AddmDate], [Gender]) VALUES (@rollno,
@stname, @stfname,@dob, @cnic, @fcelno,@address, @classname, @addmdate, @gender)";

[Link]("@rollno", [Link]);

[Link]("@stname", [Link]);

[Link]("@stfname", [Link]);

[Link]("@dob", [Link]);

[Link]("@cnic", [Link]);

[Link]("@fcelno", [Link]);

[Link]("@address", [Link]);

[Link]("@classname", [Link]);

[Link]("@addmdate", [Link]);

[Link]("@gender", [Link]);

try

[Link]();

[Link]();

[Link]();

catch (Exception ex)


{

[Link]([Link]);

public void Addattendence(AddStdAttendence add)

// StudentInfo add =new StudentInfo();

OleDbCommand cmd = new OleDbCommand();

[Link] = con;

[Link] = "INSERT INTO


StdAttendence([RollNO],[StName],[AttDate],[Class],[Attendence]) VALUES (@rollno,
@stname,@attdate,@class,@attn)";

[Link]("@rollno", [Link]);

[Link]("@stname", [Link]);

[Link]("@attdate", [Link]);

[Link]("@class", [Link]);

[Link]("@attn", [Link]);

try

[Link]();

[Link]();
[Link]();

catch (Exception ex)

[Link]([Link]);

public void Addclass(AddeClass add)

// StudentInfo add =new StudentInfo();

OleDbCommand cmd = new OleDbCommand();

[Link] = con;

[Link] = "INSERT INTO Class([ClassName]) VALUES (@name)";

[Link]("@name", [Link]);

try

[Link]();

[Link]();

[Link]();

}
catch (Exception ex)

[Link]([Link]);

public void list_DataView(string strSQL, ListView myList, string A)

[Link]();

try

OleDbCommand cmd = new OleDbCommand(strSQL, con);

[Link]();

OleDbDataReader dr = [Link]();

while ([Link]())

ListViewItem lItem = new ListViewItem();

for (int i = 0; i < [Link]; i++)

[Link][0].Text=A;
[Link](dr[i].ToString());

[Link](lItem);

int rCount = [Link];

if (rCount % 2 == 1)

//[Link] = [Link];

[Link] = [Link](((int)(((byte)(208)))),
((int)(((byte)(234)))), ((int)(((byte)(189)))));

else

[Link] = [Link];

[Link]();
[Link]();

[Link]();

catch (Exception exp)

[Link]([Link]);

public void list_DataView(string strSQL, ListView myList )

[Link]();

try

OleDbCommand cmd = new OleDbCommand(strSQL, con);

[Link]();

OleDbDataReader dr = [Link]();

while ([Link]())

ListViewItem lItem = new ListViewItem(dr[0].ToString());

for (int i = 1; i < [Link]; i++)


{

[Link](dr[i].ToString());

[Link](lItem);

int rCount = [Link];

if (rCount % 2 == 1)

//[Link] = [Link];

[Link] = [Link](((int)(((byte)(208)))),
((int)(((byte)(234)))), ((int)(((byte)(189)))));

else

[Link] = [Link];

}
}

[Link]();

[Link]();

[Link]();

catch (Exception exp)

[Link]([Link]);

[Link]();

You might also like