这样的通用类和DAL代码是存储过程吗?
DAL//修改publicstaticboolUpdateStuInfo(StuInfostu){stringstrsql="updatestuInfoset"+"stu...
DAL
//修改
public static bool UpdateStuInfo(StuInfo stu)
{
string strsql = "update stuInfo set "
+"stuName = @stuName,"
+"stuAge = @stuAge,"
+"stuSex = @stuSex,"
+"stuAdress = @stuAdress where stuNo=@stuNo";
//strsql += ";@@identity";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@stuName",stu.stuName),
new SqlParameter("@stuNo",stu.stuNo),
new SqlParameter("@stuAge",stu.stuAge),
new SqlParameter("@stuSex",stu.stuSex),
new SqlParameter("@stuAdress",stu.stuAdress)
};
int count = DBHelper.ExecuteCommand(strsql,para);
if (count > 0)
{
return true;
}
else
{
return false;
}
}
public static int AddStu(StuInfo stu)
{
string strsql = "insert into stuInfo(stuName,stuNo,stuAge,stuSex,stuAdress)"+
"values(@stuName,@stuNo,@stuAge,@stuSex,@stuAdress)";
//strsql += ";@@identity";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@stuName",stu.stuName),
new SqlParameter("@stuNo",stu.stuNo),
new SqlParameter("@stuAge",stu.stuAge),
new SqlParameter("@stuSex",stu.stuSex),
new SqlParameter("@stuAdress",stu.stuAdress)
};
int result= DBHelper.ExecuteCommand(strsql,para);
return result;
}
}
通用类=================================
public static class DBHelper
{
private static SqlConnection connection;
public static SqlConnection Connection
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["MyOfficeConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
if (connection == null)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Closed)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
}
public static SqlDataReader GetReader(string safeSql)
{
SqlCommand cmd = new SqlCommand(safeSql, Connection);
SqlDataReader reader = cmd.ExecuteReader();
return reader;
reader.Close();
reader.Dispose();
} 展开
//修改
public static bool UpdateStuInfo(StuInfo stu)
{
string strsql = "update stuInfo set "
+"stuName = @stuName,"
+"stuAge = @stuAge,"
+"stuSex = @stuSex,"
+"stuAdress = @stuAdress where stuNo=@stuNo";
//strsql += ";@@identity";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@stuName",stu.stuName),
new SqlParameter("@stuNo",stu.stuNo),
new SqlParameter("@stuAge",stu.stuAge),
new SqlParameter("@stuSex",stu.stuSex),
new SqlParameter("@stuAdress",stu.stuAdress)
};
int count = DBHelper.ExecuteCommand(strsql,para);
if (count > 0)
{
return true;
}
else
{
return false;
}
}
public static int AddStu(StuInfo stu)
{
string strsql = "insert into stuInfo(stuName,stuNo,stuAge,stuSex,stuAdress)"+
"values(@stuName,@stuNo,@stuAge,@stuSex,@stuAdress)";
//strsql += ";@@identity";
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@stuName",stu.stuName),
new SqlParameter("@stuNo",stu.stuNo),
new SqlParameter("@stuAge",stu.stuAge),
new SqlParameter("@stuSex",stu.stuSex),
new SqlParameter("@stuAdress",stu.stuAdress)
};
int result= DBHelper.ExecuteCommand(strsql,para);
return result;
}
}
通用类=================================
public static class DBHelper
{
private static SqlConnection connection;
public static SqlConnection Connection
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["MyOfficeConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
if (connection == null)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Closed)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
}
public static SqlDataReader GetReader(string safeSql)
{
SqlCommand cmd = new SqlCommand(safeSql, Connection);
SqlDataReader reader = cmd.ExecuteReader();
return reader;
reader.Close();
reader.Dispose();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询