Expand|Select|Wrap|Line Numbers
- namespace MLMLocalAdmin
- {
- public partial class frmAddDistributor : Form
- {
- public frmAddDistributor()
- {
- InitializeComponent();
- }
- private void btnSave2_Click(object sender, EventArgs e)
- {
- if (txtTianshiCode.Text == "")
- {
- MessageBox.Show("Please enter the distributor's Tianshi code");
- }
- else if (txtFullname.Text == "")
- {
- MessageBox.Show("Please enter the distributor's full name");
- }
- else if (txtGender2.Text == "")
- {
- MessageBox.Show("Please enter the gender");
- }
- else if (txtNRC.Text == "")
- {
- MessageBox.Show("Please enter the NRC or ID number");
- }
- else
- {
- //stores the values entered as variables
- string tianshiCode = txtTianshiCode.Text;
- string fullname = txtFullname.Text;
- string gender = txtGender2.Text;
- string nrc = txtNRC.Text;
- string nationality = txtNationality.Text;
- string birthDate = txtBirthDate.Text;
- string address = txtAddress.Text;
- string postalCode = txtPostalCode.Text;
- string city = txtCity.Text;
- string stateProv = txtStateProv.Text;
- string homeTel = txtHomeTel.Text;
- string officeTel = txtOfficeTel.Text;
- string mobileTel = txtMobileTel.Text;
- string email = txtEmail.Text;
- string joinDate = txtJoinDate.Text;
- string sponsorTianshiCode = txtSponsorTianshiCode.Text;
- //establishes a connection with the database
- SqlConnection cn;
- SqlCommand cmd;
- //SqlDataReader datareader;
- string sql;
- try
- {
- // this query is for insertion into the distributor table
- sql = "INSERT INTO Distributor (tianshiCode, fullName, gender, NRC_ID, nationality, birthDate, address, postalCode, city, stateProvince, homeTel, officeTel, mobileTel, email, sponsorTianshiCode, joinDate)";
- sql += String.Format("VALUES, @tianshiCode, @fullname, @gender, @nrc, @nationality, @birthDate, @address, @postalCode, @city, @stateProv, @homeTel, @officeTel, @mobileTel, @email, @sponsorTianshiCode, @joinDate");
- cn = new SqlConnection(Properties.Settings.Default.MLM_DB1ConStr);
- cmd = new SqlCommand(sql, cn);
- cmd.CommandText = sql;
- cmd.CommandType = CommandType.Text;
- cmd.Parameters.AddWithValue("@tianshiCode", txtTianshiCode.Text);
- cmd.Parameters.AddWithValue("@fullName", txtFullname.Text);
- cmd.Parameters.AddWithValue("@gender", txtGender2.Text);
- cmd.Parameters.AddWithValue("@nrc", txtNRC.Text);
- cmd.Parameters.AddWithValue("@nationality", txtNationality.Text);
- cmd.Parameters.AddWithValue("@birthDate", txtBirthDate.Text);
- cmd.Parameters.AddWithValue("@address", txtAddress.Text);
- cmd.Parameters.AddWithValue("@postalCode", txtPostalCode.Text);
- cmd.Parameters.AddWithValue("@city", txtCity.Text);
- cmd.Parameters.AddWithValue("@stateProv", txtStateProv.Text);
- cmd.Parameters.AddWithValue("@homeTel", txtHomeTel.Text);
- cmd.Parameters.AddWithValue("@officeTel", txtOfficeTel.Text);
- cmd.Parameters.AddWithValue("@mobileTel", txtMobileTel.Text);
- cmd.Parameters.AddWithValue("@email", txtEmail.Text);
- cmd.Parameters.AddWithValue("@sponsorTianshiCode", txtSponsorTianshiCode.Text);
- cmd.Parameters.AddWithValue("@joinDate", txtJoinDate.Text);
- cn.Open(); //opens connection
- cmd.ExecuteNonQuery(); //writes to the database
- MessageBox.Show("Update Successful!!");
- }
- catch (SqlException ex)
- {
- throw new Exception("Error Inserting", ex);
- }
- cn.Close();
- } //closes the else block
- }
- private void addNewToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- }
- private void frmAddDistributor_Load(object sender, EventArgs e)
- {
- }
- }
- }
System.Exception was unhandled
Message="Error Inserting"
Source="MLMLocalAdmin"
StackTrace:
at MLMLocalAdmin.frmAddDistributor.btnSave2_Click(Obj ect sender, EventArgs e) in C:\Users\Chis\Documents\Visual Studio 2005\Projects\MLMLocalAdmin\MLMLocalAdmin\frmAddDi stributor.cs:line 120
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MLMLocalAdmin.Program.Main() in C:\Users\Chis\Documents\Visual Studio 2005\Projects\MLMLocalAdmin\MLMLocalAdmin\Program. cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Can somebody please help me!!!