c#怎么样把输入表的数据添加到数据库
1个回答
展开全部
做过一个三层架构的例子,DAL层代码:
public
bool
Insert(Casepsinfo
PsCase)
{
string
strSql
=
"insert
into
tb_Casepsinfo
(CaseNum,WrittenPeop,WrittenComments,WrittenDate)values(@CaseNum,@WrittenPeop,@WrittenComments,@WrittenDate)";
SqlParameter[]
para
={
new
SqlParameter
("@CaseNum",SqlDbType
.VarChar
),
new
SqlParameter
("@WrittenPeop",SqlDbType
.VarChar
),
new
SqlParameter
("@WrittenComments",SqlDbType
.VarChar
),
new
SqlParameter
("@WrittenDate",SqlDbType
.VarChar
)
};
para[0].Value
=
PsCase.CaseNum;
para[1].Value
=
PsCase.WrittenPeop;
para[2].Value
=
PsCase.WrittenComments;
para[3].Value
=
PsCase.WrittenDate;
int
result
=
sqlHelper.ExecuteSql(strSql,
para);
if
(result
>
0)
{
return
true;
}
else
{
return
false;
}
}
BLL层:
public
bool
Insert(Casepsinfo
PsCase)
{
return
psCaseDal.Insert(PsCase);
}
界面层调用
public
bool
Insert(Casepsinfo
PsCase)
{
string
strSql
=
"insert
into
tb_Casepsinfo
(CaseNum,WrittenPeop,WrittenComments,WrittenDate)values(@CaseNum,@WrittenPeop,@WrittenComments,@WrittenDate)";
SqlParameter[]
para
={
new
SqlParameter
("@CaseNum",SqlDbType
.VarChar
),
new
SqlParameter
("@WrittenPeop",SqlDbType
.VarChar
),
new
SqlParameter
("@WrittenComments",SqlDbType
.VarChar
),
new
SqlParameter
("@WrittenDate",SqlDbType
.VarChar
)
};
para[0].Value
=
PsCase.CaseNum;
para[1].Value
=
PsCase.WrittenPeop;
para[2].Value
=
PsCase.WrittenComments;
para[3].Value
=
PsCase.WrittenDate;
int
result
=
sqlHelper.ExecuteSql(strSql,
para);
if
(result
>
0)
{
return
true;
}
else
{
return
false;
}
}
BLL层:
public
bool
Insert(Casepsinfo
PsCase)
{
return
psCaseDal.Insert(PsCase);
}
界面层调用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询