using System;
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MySchoolDAL;
namespace Student_单测
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
StudentDAL stu=new StudentDAL();
DataTable tab= stu.GetALLStudent();
foreach (DataRow item in tab.Rows)
{
Console.WriteLine(item["StudentNo"]);
}
}
}
}
StudentDAL层
public DataTable GetALLStudent(string name)
{
string str = SqlHelper.constr;
SqlConnection con = new SqlConnection(str);
string sql = "select * from Student where studentname=@name";
SqlParameter pare = new SqlParameter("@name", name);
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add(pare);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "info");
return ds.Tables["info"];
}