数据不能加入,请帮助
问题: 页面可以加,但是添加之后,不能将数据插入。代码:1、
public void AddPatient(string nName, int nSex, string nBrithday, int nMarriage, string nIDcard, string nHometown, string nUnit, string nPhone, string nContactName, string nContactRelaion, string nContactAddress, string nContactPhone)
{
HISDataContext db = new HISDataContext();
try
{
Patient pat = new Patient { Name = nName, Sex = nSex, Brithday = nBrithday, Marriage = nMarriage, IDCard = nIDcard, Hometown = nHometown, Unit = nUnit, phone = nPhone, ContactName = nContactName, ContactRelaion = nContactRelaion, ContactAddress = nContactAddress, ContactPhone = nContactPhone, CreatTime = DateTime.Now.ToLongTimeString() };
db.Patient.InsertOnSubmit(pat);
db.SubmitChanges();
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
代码表2
rotected void btnAddPatient_Click(object sender, EventArgs e)
{
if(!Page.IsValid ==true )
{
PatientDA patien= new PatientDA ();
try
{
patien.AddPatient(txtPatientName.Text.Trim(), Int32.Parse(ddlSex.SelectedValue), txtBrithday.Text.Trim(), Int32.Parse(ddlMarriage.SelectedValue), txtIDCard.Text.Trim (), txtHometowm.Text.Trim (), txtUnit.Text, txtPhone.Text.Trim (), txtRelaionName.Text.Trim (), txtRelaion.Text,txtContactAddr.Text.Trim() , txtContactPhone.Text.Trim ());
Response.Write("<script>alert('添加新病人成功!')</script>");
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
} --------------------编程问答-------------------- 这样看不出来,打断点调试一下。。 --------------------编程问答-------------------- NorthwindDataContext db = new NorthwindDataContext();
var newPatient = new Customer {Name = nName, Sex = nSex};
db.Patient.InsertOnSubmit(newPatient);
db.SubmitChanges();
字段类型是否一致 --------------------编程问答-------------------- 调试看看 db.Patient.InsertOnSubmit(pat);
db.SubmitChanges(); 属性值 --------------------编程问答-------------------- 谢谢回复!
断点在
Patient pat = new Patient { Name = nName, Sex = nSex, Brithday = nBrithday, Marriage = nMarriage, IDCard = nIDcard, Hometown = nHometown, Unit = nUnit, phone = nPhone, ContactName = nContactName, ContactRelaion = nContactRelaion, ContactAddress = nContactAddress, ContactPhone = nContactPhone, CreatTime = DateTime.Now.ToLongTimeString() };
--------------------编程问答-------------------- 问题解决了没? --------------------编程问答-------------------- 没有,我试了一下,数据类型是没有错了。不知道怎么办哪?谢谢了! --------------------编程问答-------------------- 断点调试可以一步步跟踪程序的运行过程,一般情况下就知道那些地方错了。
vs 2005断点调试
http://blog.csdn.net/chinastory/archive/2008/10/28/3168904.aspx --------------------编程问答-------------------- Int32.Parse的地方
最好是换成Convert.ToInt32();
catch(...){
Console.write(ex.message.toString());//打印出来!!
}
debug调试!! --------------------编程问答-------------------- 谢谢回复,对这个还是第一次接触,谢你的指点,但不知我怎么去设条件哪?? --------------------编程问答--------------------
这个好像是没有问题的。 --------------------编程问答-------------------- 答案找到,是一个逻辑错误。
补充:.NET技术 , ASP.NET