Xem mẫu

L p trình .NET và C#
Lecture 14:

SQL read and write
TS ào Nam Anh
UTM, Khoa KH&CN

1

Resources
Các gi i pháp l p trình C#, Nguy n Ng c Bình Phương - Thái Thanh Phong
Allen Jones. C# Programmer's Cookbook. Microsoft Press, 2004
John Connell. Coding Techniques for Microsoft Visual Basic .NET. Microsoft
Press, 2002.
Harvey M. Deitel, Paul J. Deitel, & Tem R. Nieto. Visual Basic .NET How to
Program, Second Edition. Prentice Hall, 2002.
Jose Mojica. C# and VB .NET Conversion Pocket Reference. O'Reilly, 2002.
James Avery. Ten Must-Have Tools Every Developer Should Download Now.
MSDN Magazine, 2004.
Karl Moore. The Ultimate VB.NET and ASP.NET Code Book. Apress, 2003
Matthew MacDonald. Microsoft Visual Basic .NET Programmer's Cookbook.
Microsoft Press, 2003.
Mark Schmidt & Simon Robinson. Microsoft Visual C# .NET 2003 Developer's
Cookbook. Sams Publishing, 2003.
Dương Quang Thi n. L p trình Visual C# th nào? Nhà xu t b n T ng H p TP.
H Chí Minh, 2005.
Nguy n Ng c Bình Phương & Lê Tr n Nh t Quỳnh. Các gi i pháp l p trình
Visual Basic .NET. Nhà xu t b n Giao thông V n t i, 2006
www.msdn.microsoft.com, www.codeproject.com, www.msd2d.com,
www.developersdex.com, www.windowsforms.net, www.gotdotnet.com,
www.codeguru.com, www.developerfusion.com

2

Introduction
how to read and wrire to a SQL Server

3

SqlCommand myCommand= new
SqlCommand("INSERT INTO table
(Column1, Column2) " + "Values ('string', 1)",
myConnection);

myCommand.ExecuteNonQuery();

4

SqlDataReader
try { SqlDataReader myReader = null;
SqlCommand myCommand = new
SqlCommand("select * from table", myConnection);
myReader = myCommand.ExecuteReader();
while(myReader.Read())
{ Console.WriteLine(myReader["Column1"].ToString());
Console.WriteLine(myReader["Column2"].ToString()
); } }
catch (Exception e)
{ Console.WriteLine(e.ToString()); }
5

nguon tai.lieu . vn