TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bineesh Viswanath
NA
1k
776.4k
Save Function in ADO.NET
Jul 17 2013 12:42 AM
Sir, I am now in a ADO.NET Project.
here I uploading a form named frmStudent. There are three tapPages for this from. I uploading each tabPage.
First TabPage;
Second TabPage
and Third TabPage
These all are my form.
and I want from this form is the Save function.
I did the coding for this function, but not getting the result. This function has no any error
nothing error shows when when I hit btnSave,
please check out the logical mistake in these functions.
I did the stored procedure function and called this in spclass.
here is the spclass function;
public void studentAdd(studentInfo infoStudent)
{
try
{
if (sqlCon.State == ConnectionState.Closed)
{
sqlCon.Open();
}
SqlCommand sqlCmd = new SqlCommand("studentAdd", sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add("@admissionNo", SqlDbType.VarChar).Value = infoStudent.admissionNo;
sqlCmd.Parameters.Add("@admissionDate", SqlDbType.VarChar).Value = infoStudent.admissionDate;
sqlCmd.Parameters.Add("@applicationFormNo", SqlDbType.VarChar).Value = infoStudent.applicationFormNo;
//sqlCmd.Parameters.Add("@schoolCode", SqlDbType.Decimal).Value = infoStudent.schoolCode;
//sqlCmd.Parameters.Add("@classId", SqlDbType.Decimal).Value = infoStudent.classId;
// sqlCmd.Parameters.Add("@divisionId", SqlDbType.Decimal).Value = infoStudent.divisionId;
sqlCmd.Parameters.Add("@firstName", SqlDbType.VarChar).Value = infoStudent.firstName;
sqlCmd.Parameters.Add("@middleName", SqlDbType.VarChar).Value = infoStudent.middleName;
sqlCmd.Parameters.Add("@lastName", SqlDbType.VarChar).Value = infoStudent.lastName;
sqlCmd.Parameters.Add("@initialExpansion", SqlDbType.VarChar).Value = infoStudent.initialExpansion;
sqlCmd.Parameters.Add("@DOB", SqlDbType.VarChar).Value = infoStudent.DOB;
sqlCmd.Parameters.Add("@Gender", SqlDbType.VarChar).Value = infoStudent.Gender;
sqlCmd.Parameters.Add("@fatherName", SqlDbType.VarChar).Value = infoStudent.fatherName;
sqlCmd.Parameters.Add("@fatherOccupation", SqlDbType.VarChar).Value = infoStudent.fatherOccupation;
sqlCmd.Parameters.Add("@motherName", SqlDbType.VarChar).Value = infoStudent.motherName;
sqlCmd.Parameters.Add("@motherOccupation", SqlDbType.VarChar).Value = infoStudent.motherOccupation;
sqlCmd.Parameters.Add("@guardianName", SqlDbType.VarChar).Value = infoStudent.guardianName;
sqlCmd.Parameters.Add("@guardianOccupation", SqlDbType.VarChar).Value = infoStudent.guardianOccupation;
sqlCmd.Parameters.Add("@Residence", SqlDbType.VarChar).Value = infoStudent.Residence;
sqlCmd.Parameters.Add("@relationShip", SqlDbType.VarChar).Value = infoStudent.relationShip;
sqlCmd.Parameters.Add("@Nationality", SqlDbType.VarChar).Value = infoStudent.Nationality;
sqlCmd.Parameters.Add("@bloodGroup", SqlDbType.VarChar).Value = infoStudent.bloodGroup;
sqlCmd.Parameters.Add("@religion", SqlDbType.VarChar).Value = infoStudent.Religion;
sqlCmd.Parameters.Add("@belongTo", SqlDbType.VarChar).Value = infoStudent.belongTo;
sqlCmd.Parameters.Add("@Caste", SqlDbType.VarChar).Value = infoStudent.Caste;
sqlCmd.Parameters.Add("@Quota", SqlDbType.VarChar).Value = infoStudent.Quota;
sqlCmd.Parameters.Add("@placeOfBirth", SqlDbType.VarChar).Value = infoStudent.placeofBirth;
sqlCmd.Parameters.Add("@Medium", SqlDbType.VarChar).Value = infoStudent.Medium;
sqlCmd.Parameters.Add("@firstlanguagePaper1", SqlDbType.VarChar).Value = infoStudent.firstlanguagePaper1;
sqlCmd.Parameters.Add("@firstlanguagePaper2", SqlDbType.VarChar).Value = infoStudent.firstlanguagePaper2;
sqlCmd.Parameters.Add("@secondLanguage", SqlDbType.VarChar).Value = infoStudent.secondLanguage;
sqlCmd.Parameters.Add("@thirdLanguage", SqlDbType.VarChar).Value = infoStudent.thirdLanguage;
sqlCmd.Parameters.Add("@feeConcession", SqlDbType.VarChar).Value = infoStudent.feeConcession;
sqlCmd.Parameters.Add("@idMark1", SqlDbType.VarChar).Value = infoStudent.idMark1;
sqlCmd.Parameters.Add("@idMark2", SqlDbType.VarChar).Value = infoStudent.idMark2;
sqlCmd.Parameters.Add("@motherTongue", SqlDbType.VarChar).Value = infoStudent.motherTongue;
sqlCmd.Parameters.Add("@Immunised", SqlDbType.VarChar).Value = infoStudent.Immunised;
sqlCmd.Parameters.Add("@vaccinationDate", SqlDbType.VarChar).Value = infoStudent.vaccinationDate;
sqlCmd.Parameters.Add("@houseName", SqlDbType.VarChar).Value = infoStudent.houseName;
sqlCmd.Parameters.Add("@nameInMotherTongue", SqlDbType.VarChar).Value = infoStudent.nameinMotherTongue;
sqlCmd.Parameters.Add("@permanentAddress", SqlDbType.VarChar).Value = infoStudent.permanentAddress;
sqlCmd.Parameters.Add("@permanentpostalCode", SqlDbType.VarChar).Value = infoStudent.permanentpostalCode;
sqlCmd.Parameters.Add("@annualIncome", SqlDbType.Decimal).Value = infoStudent.annualIncome;
sqlCmd.Parameters.Add("@permanentCountry", SqlDbType.VarChar).Value = infoStudent.permanentCountry;
sqlCmd.Parameters.Add("@presentAddress", SqlDbType.NVarChar).Value = infoStudent.presentAddress;
sqlCmd.Parameters.Add("@presentpostalCode", SqlDbType.VarChar).Value = infoStudent.presentpostalCode;
sqlCmd.Parameters.Add("@presentCountry", SqlDbType.VarChar).Value = infoStudent.presentCountry;
sqlCmd.Parameters.Add("@phoneNo", SqlDbType.VarChar).Value = infoStudent.phoneNo;
sqlCmd.Parameters.Add("@mobileNo", SqlDbType.VarChar).Value = infoStudent.mobileNo;
sqlCmd.Parameters.Add("@studentEmail", SqlDbType.VarChar).Value = infoStudent.studentEmail;
sqlCmd.Parameters.Add("@parentEmail", SqlDbType.VarChar).Value = infoStudent.parentEmail;
sqlCmd.Parameters.Add("@fatherPhone", SqlDbType.VarChar).Value = infoStudent.fatherPhone;
sqlCmd.Parameters.Add("@motherPhone", SqlDbType.VarChar).Value = infoStudent.motherPhone;
sqlCmd.Parameters.Add("@guardianPhone1", SqlDbType.VarChar).Value = infoStudent.guardianPhone1;
sqlCmd.Parameters.Add("@guardianPhone2", SqlDbType.VarChar).Value = infoStudent.guardianPhone2;
int incount = sqlCmd.ExecuteNonQuery();
if (incount > 0)
{
MessageBox.Show("SAVED SUCCESSFULLY");
}
else
{
MessageBox.Show("DATA EXISTS ALREADY");
}
}
catch (Exception ex)
{
MessageBox.Show("studSP01" + ex.Message);
}
finally
{
sqlCon.Close();
}
}
and then I calles this function in btnsave_Click in frmStudent. here is the code
private void btnSave_Click(object sender, EventArgs e)
{
try
{
studentSp SPStudent = new studentSp();
studentInfo infoStudent = new studentInfo();
infoStudent.admissionNo = decimal.Parse(txtAdmissionNo.Text);
infoStudent.admissionDate =DateTime.Parse(dtpAdmissionDate.Text);
infoStudent.applicationFormNo = decimal.Parse(txtApplicationFormNo.Text);
infoStudent.schoolCode = DecStudent;
//infoStudent.classId = decimal.Parse(cmbClassName.SelectedValue.ToString());
//infoStudent.divisionId = decimal.Parse(cmbDivision.SelectedValue.ToString());
infoStudent.firstName = txtFirstName.Text;
infoStudent.middleName = txtMiddleName.Text;
infoStudent.lastName = txtLastName.Text;
infoStudent.initialExpansion = txtInitialExpansn.Text;
infoStudent.DOB =DateTime.Parse(dtpDob.Text);
infoStudent.Gender = rbtnMale.Text;
infoStudent.fatherName = txtFatherName.Text;
infoStudent.fatherOccupation = txtFatherJob.Text;
infoStudent.motherName = txtMotherName.Text;
infoStudent.motherOccupation = txtMotherJob.Text;
infoStudent.guardianName = txtGuardianName.Text;
infoStudent.guardianOccupation = txtGuardianJob.Text;
infoStudent.Residence = txtResidence.Text;
infoStudent.relationShip = txtRelationship.Text;
infoStudent.Nationality = txtNationality.Text;
infoStudent.bloodGroup = cmbBloodGrp.SelectedItem.ToString();
infoStudent.Religion = cmbReligion.SelectedItem.ToString();
infoStudent.belongTo = cmbStudentBelongs.SelectedItem.ToString();
infoStudent.Caste = cmbCaste.SelectedItem.ToString();
infoStudent.Quota = cmbQuota.SelectedItem.ToString();
infoStudent.placeofBirth = txtBirthPlace.Text;
infoStudent.Medium = txtMedium.Text;
infoStudent.firstlanguagePaper1 = cmbfirststLangPaper1.SelectedItem.ToString();
infoStudent.firstlanguagePaper2 = cmbfirstLangPaper2.SelectedItem.ToString();
infoStudent.secondLanguage = cmb2ndLang.SelectedItem.ToString();
infoStudent.thirdLanguage = cmb3rdLang.SelectedItem.ToString();
infoStudent.feeConcession = cmbFeeConcession.SelectedItem.ToString();
infoStudent.idMark1 = txtIdMark1.Text;
infoStudent.idMark2 = txtIdMark2.Text;
infoStudent.motherTongue = txtMotherTng.Text;
infoStudent.Immunised = cmbWhetherimmunsed.SelectedItem.ToString();
infoStudent.vaccinationDate = DateTime.Parse(dtplastVaccinationDate.Text);
infoStudent.houseName = cmbStudentHouseName.SelectedItem.ToString();
infoStudent.nameinMotherTongue = txtNameinMothertongue.Text;
infoStudent.permanentAddress = txtPermntAddress.Text;
infoStudent.permanentpostalCode = decimal.Parse(txtpermpostalCode.Text.ToString());
infoStudent.annualIncome = decimal.Parse(txtAnnualIncome.Text);
infoStudent.permanentCountry = cmbPermanentCountry.SelectedItem.ToString();
infoStudent.presentAddress = txtPresentAddress.Text;
infoStudent.presentpostalCode = decimal.Parse(txtpresentpostalCode.Text);
infoStudent.presentCountry = cmbPresentCountry.SelectedItem.ToString();
infoStudent.phoneNo = decimal.Parse(txtFonNo.Text.ToString());
infoStudent.mobileNo = decimal.Parse(txtmobileNo.Text.ToString());
infoStudent.studentEmail = txtStudentEmail.Text;
infoStudent.parentEmail = txtParentEmail.Text;
infoStudent.fatherPhone = decimal.Parse(txtFatherfonNo.Text.ToString());
infoStudent.motherPhone = decimal.Parse(txtmotherfonNo.Text.ToString());
infoStudent.guardianPhone1 = decimal.Parse(txtGuardianfoneNo.Text.ToString());
infoStudent.guardianPhone2 = decimal.Parse(txtguardianFon1.Text.ToString());
infoStudent.Photo = Logo;
SPStudent.studentAdd(infoStudent);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
If you want more from my code, please mention
Reply
Answers (
8
)
Connect to Interbase 7.5
How to avoid the duplicate Entry ?