0% found this document useful (0 votes)
4 views1 page

Step First Final Exam

Uploaded by

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

Step First Final Exam

Uploaded by

Vi Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

part1: Initial

- Create project:
+ ASP.Net
+ Empty project
+ Webform
- Create database (SQL sever of Visual Studio):
+ 1 first many later
+ Close after update a new table to avoid conflict
+ Create Foreign key from many to 1
- Insert Data to database:
- Create Image folder (inside of project folder like: .../abc/abc/Image)
- Create Connect Class (name Xuly)
+ Include 2 libraries:
using System.Data;
using System.Data.SqlClient;
Part2: Open Connect Method
+ In class Xuly:
SqlConnection con;
+ Create open connect method (ketnoi) :
private void ketnoi()
{
//Create value for SqlConnection
con = new SqlConnection(@" <---> ")
con.Open(); //Open connect
}
Part3: Sql connection path
+ Choose Database file's properties
=> coppy connect string
=> parst in <---> above
Part4: Close Connect Method and Get Database
+ Create close connect method (dongketnoi) :
// If connect is opening
if (con.State == ConnectionState.Open)
con.Close();
+ Create get database method (which datatype is DataTable and an input value
is an sql string)
public DataTable getdata(string q)
{
//Declare DataTable Opject
DataTable dt = new DataTable();

try
{
ketnoi();//Open connection
SqlDataAdapter adap = new SqlDataAdapter(sql, con);
adap.Fill(dt); //Input data in adap into dt variaty
}
catch {dt = null;}
finally {dongketnoi();}

//Return dt when done (Write in early to not see error warning)


return dt;
}
PartFinal:

You might also like