这是我的aspx.cs
页面,这些代码应该将值插入到数据库中,但目前它并不好,它没有插入到数据库中,我没有收到任何错误但插入没有发生,我不知道出了什么问题。IS有可能SqlException
吗?或任何其他问题?
protected void btnSkipSubmit_Click(object sender, EventArgs e)
{
int random = 0;
bool isValidInt = int.TryParse(txtrandom.Text, out random);
//string dummmy = "D";
//int dum = 0;
Patient p = new Patient();
//PatientBill pb = new PatientBill();
myConnection obj1 = new myConnection();
DateTime sdt = DateTime.Now;
// string a;
string str = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
string cmdString = "";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(cmdString, con);
SqlTransaction transaction;
if (isValidInt)
{
for (int i = 0; i < random; i++)
{
//a = obj1.fnSkipPatient(p);
string dummmy = "D";
int dum = 0;
//DateTime sdt = DateTime.Now;
cmdString = "INSERT INTO Patient_Data(PatientID,PatientName,F_H_G,F_H_GName,AgeOnRegn,Email,ContactNo,Gender,Married,AddressLine1,AddressLine2,City,PinCode,Religion,Occupation,RegTime,VisitDate,CurrDept,NextDept,PayID,PayDet1,PayDet2,PayDet3,PayValidity,Archived,UpdateUser,UpdateShift,UpdateDate,LocID,AddressLine3,Remark) VALUES (@PatientID,@PatientName,@F_H_G,@F_H_GName,@AgeOnRegn,@Email,@ContactNo,@Gender,@Married,@AddrLine1,@AddrLine2,@City,@PinCode,@Religion,@Occupation,@RegTime,@VisitDate,@CurrDept,@NextDept,@PayID,@PayDet1,@PayDet2,@PayDet3,@PayValidity,@Archived,@UpdateUser,@UpdateShift,@UpdateDate,@LocID,@AddrLine3,@Remark)";
con = new SqlConnection(str);
try
{
//log.Debug("Entering fnAddPatient method-Function to add a new patient into the database,generate registration bill");
con.Open();
transaction = con.BeginTransaction();
cmd = new SqlCommand(cmdString, con, transaction);
cmd.Parameters.Add("@PatientID", SqlDbType.VarChar, 12);
cmd.Parameters["@PatientID"].Value = p.HospitalNo;
cmd.Parameters.Add("@PatientName", SqlDbType.VarChar, 30);
cmd.Parameters["@PatientName"].Value = dummmy;
cmd.Parameters.Add("@F_H_G", SqlDbType.VarChar, 1);
cmd.Parameters["@F_H_G"].Value = dummmy;
cmd.Parameters.Add("@F_H_GName", SqlDbType.VarChar, 30);
cmd.Parameters["@F_H_GName"].Value = dummmy;
cmd.Parameters.Add("@AgeOnRegn", SqlDbType.Int);
cmd.Parameters["@AgeOnRegn"].Value = dum;
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 40);
cmd.Parameters["@Email"].Value = dummmy;
cmd.Parameters.Add("@ContactNo", SqlDbType.VarChar, 12);
cmd.Parameters["@ContactNo"].Value = dummmy;
cmd.Parameters.Add("@Gender", SqlDbType.VarChar, 1);
cmd.Parameters["@Gender"].Value = dummmy;
cmd.Parameters.Add("@Married", SqlDbType.VarChar, 1);
cmd.Parameters["@Married"].Value = dummmy;
cmd.Parameters.Add("@AddrLine1", SqlDbType.VarChar, 100);
cmd.Parameters["@AddrLine1"].Value = dummmy;
cmd.Parameters.Add("@AddrLine2", SqlDbType.VarChar, 100);
cmd.Parameters["@AddrLine2"].Value = dummmy;
cmd.Parameters.Add("@AddrLine3", SqlDbType.VarChar, 100);
cmd.Parameters["@AddrLine3"].Value = dummmy;
cmd.Parameters.Add("@City", SqlDbType.VarChar, 20);
cmd.Parameters["@City"].Value = dummmy;
cmd.Parameters.Add("@PinCode", SqlDbType.Int);
cmd.Parameters["@PinCode"].Value = dum;
cmd.Parameters.Add("@Religion", SqlDbType.VarChar, 20);
cmd.Parameters["@Religion"].Value = dummmy;
cmd.Parameters.Add("@Occupation", SqlDbType.VarChar, 20);
cmd.Parameters["@Occupation"].Value = dummmy;
cmd.Parameters.Add("@RegTime", SqlDbType.DateTime);
cmd.Parameters["@RegTime"].Value = sdt;
cmd.Parameters.Add("@VisitDate", SqlDbType.DateTime);
cmd.Parameters["@VisitDate"].Value = sdt;
cmd.Parameters.Add("@CurrDept", SqlDbType.Int);
cmd.Parameters["@CurrDept"].Value = dum;
cmd.Parameters.Add("@NextDept", SqlDbType.Int);
cmd.Parameters["@NextDept"].Value = dum;
cmd.Parameters.Add("@PayId", SqlDbType.VarChar, 2);
cmd.Parameters["@PayId"].Value = dummmy;
cmd.Parameters.Add("@PayDet1", SqlDbType.VarChar, 15);
cmd.Parameters["@PayDet1"].Value = dummmy;
cmd.Parameters.Add("@PayDet2", SqlDbType.VarChar, 50);
cmd.Parameters["@PayDet2"].Value = dummmy;
cmd.Parameters.Add("@PayDet3", SqlDbType.VarChar, 15);
cmd.Parameters["@PayDet3"].Value = dummmy;
cmd.Parameters.Add("@PayValidity", SqlDbType.DateTime);
cmd.Parameters["@PayValidity"].Value = sdt;
cmd.Parameters.Add("@Archived", SqlDbType.VarChar, 1);
cmd.Parameters["@Archived"].Value = dummmy;
cmd.Parameters.Add("@UpdateUser", SqlDbType.VarChar, 20);
cmd.Parameters["@UpdateUser"].Value = dummmy;
cmd.Parameters.Add("@UpdateShift", SqlDbType.Int);
cmd.Parameters["@UpdateShift"].Value = dum;
cmd.Parameters.Add("@UpdateDate", SqlDbType.DateTime);
cmd.Parameters["@UpdateDate"].Value = sdt;
cmd.Parameters.Add("@PatientCount", SqlDbType.Int);
cmd.Parameters["@PatientCount"].Value = dum;
cmd.Parameters.Add("@LocId", SqlDbType.VarChar, 2);
cmd.Parameters["@LocId"].Value = dummmy;
cmd.Parameters.Add("@Remark", SqlDbType.VarChar, 100);
cmd.Parameters["@Remark"].Value = dummmy;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Clear();
string result = cmd.ExecuteNonQuery().ToString();
}
catch (Exception ex)
{
}
finally
{
con.Close();
}
}
}
}