در حال حاضر کد مربوط به این قسمت در try و catch همراه با Exception هست.
و نکته دیگه اینه که برنامه در کامپیوتر من الان مشکلی نداره . از کجا باید بفهمم خطا مربوط به چیه؟ ضمن اینکه در کامپیوتر مقصد هم تا حالا بی مشکل بوده.
اگر به جز ترای و کچ راه دیگه ای هم هست ممنون میشم بهم بگید.
هر چند تو ارور نگفته خطا مربوط به کدوم لاینه اما این تابعی رو که اسم برده بر من اینجا میذارم ببینید:
private void ConnectTodatabaseAddBook()
{
check = false;
try
{
ErrorProvider ep = new ErrorProvider();
ep.Clear();
if ((lastnametxt.Text == "") || (memberIDtxt .Text =="" ))
{
MessageBox.Show("فیلدهای ستاره دار الزامیست");
check = false;
}
else
{
ds2.Clear();
con.Open();
ada2.SelectCommand = new SqlCommand("select * from member where memberID = " + memberIDtxt.Text, con);
ada2.Fill(ds2);
con.Close();
if (ds2.Tables[0].Rows.Count >= 1)
{
MessageBox.Show("این شماره عضویت قبلا وارد شده است");
check = false;
}
else
{
bool journal = false ;
if (journalcombo.Text == "بله")
journal = true ;
int year=0;
if (yearbirth.Text != "")
year =int .Parse ( yearbirth .Text) ;
int degree = 0;
if (lastdegreetxt.Text != "")
degree = int.Parse(lastdegreetxt.Text);
int matab = 0;
if (matabyeartxt.Text!="")
matab =int .Parse ( matabyeartxt.Text);
int yjornal = 0;
if (journalyeartxt.Text!="")
yjornal =int .Parse (journalyeartxt.Text);
//int daybirth;
//if (mbirth.SelectedIndex == -1)
// daybirth = 1;
//else
// daybirth = int.Parse(dbirth.Text);
SqlCommand objCommand = new SqlCommand();
objCommand.Connection = con;
objCommand.CommandType = CommandType.Text;
objCommand.Parameters.AddWithValue("@memberID", memberIDtxt.Text);
objCommand.Parameters.AddWithValue("@name", nametxt.Text);
objCommand.Parameters.AddWithValue("@lastname", lastnametxt.Text);
objCommand.Parameters.AddWithValue("@codemelli", codemtxt.Text);
objCommand.Parameters.AddWithValue("@daybirth", int.Parse(dbirth.Text));
objCommand.Parameters.AddWithValue("@mountbirth",i nt .Parse ( mbirth.Text ));
objCommand.Parameters.AddWithValue("@yearbirth",ye ar );
objCommand.Parameters.AddWithValue("@shenasnameID" , shshtxt.Text);
objCommand.Parameters.AddWithValue("@sex", sexcombo.Text );
objCommand.Parameters.AddWithValue("@nezamID", nezamtxt.Text);
objCommand.Parameters.AddWithValue("@pro", procombo.Text );
objCommand.Parameters.AddWithValue("@degree", degreecombo.Text );
objCommand.Parameters.AddWithValue("@uniofdegree", unicombo1.Text );
objCommand.Parameters.AddWithValue("@cityofuni", cityofuni.Text);
objCommand.Parameters.AddWithValue("@uniID", unicombo.Text );
objCommand.Parameters.AddWithValue("@city", citycombo.Text );
objCommand.Parameters.AddWithValue("@address", addtxt.Text);
objCommand.Parameters.AddWithValue("@yearoflastdeg ree", degree );
objCommand.Parameters.AddWithValue("@yearofmatab", matab );
objCommand.Parameters.AddWithValue("@memtype", membertypecombo.Text);
objCommand.Parameters.AddWithValue("@journal",Conv ert .ToBoolean ( journal));
objCommand.Parameters.AddWithValue("@yearofjournal ", yjornal );
objCommand.Parameters.AddWithValue("@email", emailtxt.Text);
objCommand.Parameters.AddWithValue("@phone", phonetxt.Text);
objCommand.Parameters.AddWithValue("@mobile", mobtxt.Text);
objCommand.Parameters.AddWithValue("@fax", faxtxt.Text);
objCommand.Parameters.AddWithValue("@hos1", hos1combo.Text);
objCommand.Parameters.AddWithValue("@hosp",hospriv atecombo.Text);
objCommand.CommandText = "insert into member(memberID,name,lastname,codemelli,daybirth,m ountbirth,yearbirth,shenasnameID,sex,nezamID,uniID ,pro,degree,uniofdegree,cityofuni,city,address,yea roflastdegree,yearofmatab,memtype,journal,yearofjo urnal,email,phone,mobile,fax,hos1,hosp) values " +
"(@memberID,@name,@lastname,@codemelli,@daybirth,@ mountbirth,@yearbirth,@shenasnameID,@sex,@nezamID, @uniID,@pro,@degree,@uniofdegree,@cityofuni,@city, @address,@yearoflastdegree,@yearofmatab,@memtype,@ journal,@yearofjournal,@email,@phone,@mobile,@fax, @hos1,@hosp)";
con.Open();
objCommand.ExecuteNonQuery();
con.Close();
check = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}