asp.net操作数据库

来源:百度知道 编辑:UC知道 时间:2024/05/14 21:14:55
我想问asp.net能实现像asp里的读取数据后的赋值功能

asp:
sql="select * from [table]"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
变量A=rs("A")
变量B=rs("B")
本人初学asp.net,头大,已经习惯asp的语法了,另再请各位赐教,如何才能很快学会asp.net呢,先谢过各位

string strConn = "User ID=sa; Password=; Persist Security Info=True; Initial Catalog=TestData;Data Source=127.0.0.1";

using( SqlConnection myConnection = new SqlConnection(strConn))
{
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = "select * from ...";

// Execute the command
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader();

while(dr.Read())
{
string 变量A=rs["A"].ToString();
string 变量B=rs["B"].ToString();
}

dr.Close();
myConnection.Close();
}

我就不弄格式了啊,全部顶格给你发出来