我是一名完全没有C#基础的新手。我正在尝试从Web表单更新SQL数据库中的"Patient"表。我调用了一个我编写的WCF服务的"PatientRegistration"方法来完成此操作。当添加患者时,服务返回"True",如果失败,则返回"False"。
应用程序已构建、运行并返回"true"......但当我检查数据库时,我添加的任何患者都不会出现在表中(即使刷新后也是如此)。
有人能看出我可能错在哪里吗?以下是我这个"数据库服务"的代码:
namespace ADOWebApp2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ADODatabaseService" in code, svc and config file together.
public class ADODatabaseService : IADODatabaseService
{
public bool PatientRegistration(string hno, string fname, string lname, int pnum, string address, string email)
{
string connString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\xxxxx\\Documents\\Visual Studio 2010\\Projects\\ADOWebApp2\\ADOWebApp2\\App_Data\\ADOdb.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(connString);
string sqlquery = "select * from Patient";
SqlDataAdapter sqladapter = new SqlDataAdapter();
SqlCommandBuilder cb = new SqlCommandBuilder(sqladapter);
try
{
conn.Open();
sqladapter.SelectCommand = new SqlCommand(sqlquery, conn);
DataSet patient = new DataSet();
sqladapter.Fill(patient, "Patient");
DataRow row = patient.Tables["Patient"].NewRow();
row[0] = hno;
row[1] = fname;
row[2] = lname;
row[3] = pnum;
row[4] = address;
row[5] = email;
sqladapter.Update(patient, "Patient");
return true;
}
catch (Exception)
{
return false;
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}