beta2中的SqlConnection和SqlCommand
2024-07-21 02:23:45
供稿:網(wǎng)友
after a long struggle, i was able to install .net beta 2 but this is not the end of problems. as per as msdn documentation, it is clearly mentioned that asp.net is supported on win nt but dear bill gates fans just check out this letter from scott and you will find that asp.net is not supported on nt for some technical reasons. and that's what i experienced with lot of efforts. anyway, that's the past. now, i'm up with win 2000 and on top of that i successfully installed 123 mb of .net and mobile internet toolkit. as per as your expectations, i won't disappoint you. although, in this particular article, i won't discuss my mobile series. in this article, i'll discuss something new which i noticed when i start testing my first beta 1 based application. there are many changes in beta2 and first of them i noticed was ado.net area.
in this article, you'll see how to use sqlconnection and sqlcommand ado.net objects. first thing is, namespaces. there is no namespace called system.data.sql any more. it has been changed with system.data.sqlclient. see http://www.c-sharpcorner.com/beta%202/adonet1.asp for more details.
if you had program in beta 1, your code would look like this -
如果你用beta1編過(guò)程序,你的代碼會(huì)看起來(lái)象下面的樣子
<%@ import namespace="system.data.sql" %>
sqldatareader myreader;
sqlconnection myconnection = new sqlconnection("server=localhost;uid=sa;pwd=sa;database=shivani");
sqlcommand mycommand = new sqlcommand("select * from shivaniarea, myconnection);
try
{
myconnection.open();
mycommand.execute(out myreader);
while (myreader.read())
{
// retrieve the fields
}
and now new version of beta 2 looks like this -
現(xiàn)在新版本的beta2中看起來(lái)這樣
<%@ import namespace="system.data.sqlclient"%>
sqldatareader myreader;
sqlconnection myconnection = new sqlconnection("server=localhost;uid=sa;pwd=sa;database=shivani");
sqlcommand mycommand = new sqlcommand("select * from shivaniarea", myconnection);
try
{
myconnection.open();
myreader = mycommand.executereader;
while(myreader.read())
{
//retrieve the fields
}
}
during the testing of my mobile applications, i noticed more problems working with beta 1 code. i was having problem working with the tagprefix. any way .. i'll be coming with more articles on this matter soon and keep updating you on beta 2. in my next article, i will discuss how to deal with the problem of losing the documentnavigator class in xml and take the real use of xmldocument class.