***EDIT***
Actually, this is not a problem, code works. I am just seeking the better ways using latest available tools for C#.
***END EDIT***
Following is the connection I use for an Access DB. Would you please let me know if this connection method is ok for C# or there is a better way. I am new in C#, coming from VB6 world. I would like to learn the best and easiest way to do things as much as possible...
Thanks,
Leo
string SqlStr; ADODB.Connection Conn1; ADODB.Recordset Rs1; Conn1 = new ADODB.Connection(); Rs1 = new ADODB.Recordset(); Conn1.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Leo\\Documents\\Visual Studio 2008\\Projects\\CodeDatabase\\CodeDatabase\\CodeDatabase.mdb;Persist Security Info=False;", "", "", 0 ); SqlStr = "SELECT * FROM Codes";
// Open Recordset Rs1.Open (SqlStr, Conn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly, 0); // Check if anything in the table if (Rs1.EOF == false)
// If so, loop and get all the information to fill the list do { lstSubjects.Items.Add(Rs1.Fields["ID"].Value + "~" + Rs1.Fields["_Subject"].Value); Rs1.MoveNext(); } while (Rs1.EOF == false);
// Call CloseDatabase Conn1.Close(); Conn1 = null; }
|
Leo KoachPosted Mar 10, 2010, 3:20 PM
Here is my blog link to see all the codes...
http://www.vbdotnetheaven.com/Blogs/BlogDetail.aspx?BlogId=1951
Sam HobbsPosted Feb 23, 2010, 10:12 PM
One of the most useful parts of a data source is TableAdapters; there is not a lot of documentation of them since they exist as generated code. A TableAdapter provides typed methods and properties that make it easier to use databases.
See Visual C++ Guided Tour for a worthwhile tour, except you don't need to do them in the order they appear.