Professional Documents
Culture Documents
while (_reader.Read())
{
Nếu bạn muốn xây dựng chương trình kiểu như duyệt các bản ghi
sau đó ấn next, preview ... thì trong VS cũng có hỗ trợ bạn làm đấy. Cái DataFormWizard sẽ làm
tất cho bạn. Bạn hãy mua cuốn:
Lập trình CSDL bằng C# (tập 4) của ông Dương Quang Thiện mà đọc. Trong đó có chỉ rõ lắm.
#Region "Singleton"
#End Region
#Region "Contructor"
#End Region
#Region "Variable"
#End Region
#Region "Properties"
#End Region
#End Region
#Region "Method : Public"
#End Region
Public Sub AddParameter(ByVal name As String, ByVal type As SqlDbType, ByVal value As
Object)
Me.Command.Parameters.Add(name, type).Value = value
End Sub
#End Region
End Class
Đây là vài lớp đơn giản, và được viết rất nghiệp dư: clsConnection , clsTestDataInput
class clsConnection
{
static string STRCON ="workstation id=" + SystemInformation.ComputerName + ";packet
size=4096;integrated security=SSPI;data source=" +
"\"(local)\";persist security info=False;initial catalog=HotelV1G2";
SqlConnection conn;
SqlCommand comm;
SqlDataReader dr;
SqlDataAdapter data;
public bool Connection()
{
bool bol = true;
try
{
using (conn)
{
conn = new SqlConnection(STRCON);
conn.Open();
}
}
catch (Exception)
{
MessageBox.Show("Error connection! Check connection to sql server!!!");
Application.Exit();
}
return bol ;
}
public DataTable GetDataTable(string sql)
{
DataTable table = new DataTable();
try
{
using (data)
{
if (Connection())
{
data = new SqlDataAdapter(sql, conn);
data.Fill(table);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return table;
}
public string ExecuteSQL(string sql)
{
string error = "";
if (Connection())
{
try
{
using (comm)
{
comm = new SqlCommand();
comm.CommandText = sql;
comm.Connection = conn;
comm.ExecuteNonQuery();
}
}
catch (SqlException ex)
{
error = ex.Message;
MessageBox.Show(error);
}
}
return error;
}
..................................
==============================================================
internal static class clsTestDataInput
{
internal static Boolean CheckIsNumber(string textInput)
{
Boolean bol = false;
foreach (char letter in textInput)
{
if (char.IsDigit(letter))
{
bol = true;
}
else
{
return bol = false;
}
}
return bol;
}
}
.............................
================================================================
+ Đối với class clsConnection khi sử dụng cần tạo thể hiện
Imports System.Data.OleDB
Module Mod_Connection
Public m_user As String
Public m_pass As String
Public m_schema As String
Public DB_Connection As New OleDb.OleDbConnection
Public WithEvents Trackuser As New ClsThreadingTracking
Public TimeOut As Boolean
Dim t As Threading.Thread
End Function
End Function