i am a newbie so bare with me.. can anybody help me solve this prob.
input string was not in a correct format
this is my code... i can figure out what wrong with this ..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace WindowsFormsApplication3pmp
{
public partial class PayForm : Form
{
private ComboBox stype = new ComboBox();
private int paynosp, spAdd, payfpair;
public PayForm()
{
InitializeComponent();
}
private void Cancel_Click(object sender, EventArgs e)
{
this.Hide();
}
private void PaySrvcType_SelectedIndexChanged(object sender, EventArgs e)
{
stype.Items.Add("Baptismal");
stype.Items.Add("Special Baptismal");
stype.Items.Add("Confirmation");
stype.Items.Add("Communion");
SavePay.Click += SavePay_Click;
}
private void SavePay_Click(object sender, EventArgs e)
{
string noor = noOR.Text;
string paydate = PayDate.Value.ToShortDateString();
string payname = PayName.Text;
string stype = PaySrvcType.Text;
string stypeid = STypeID.Text;
string payfp = PayFP.Text;
string payNoSp = PayNoSp.Text;
string paytotal = payTotal.Text;
string addsp = Addsp.Text;
string AssessBy = assessBy.Text;
paynosp= Convert.ToInt32(payNoSp);
spAdd = Convert.ToInt32(addsp);
if (stype == "Baptismal")
{
stypeid += "1";
payfp += "200";
}
else if (stype == "Special Baptismal")
{
stypeid += "2";
payfp += "1000";
}
else if (stype == "Confirmation")
{
stypeid += "3";
payfp += "100";
}
payfpair = Convert.ToInt32(payfp);
paytotal += (payfpair +(paynosp * spAdd));
DialogResult msgbox = new DialogResult();
try
{
if (PayName.Text == "" || assessBy.Text == "" )
{
MessageBox.Show("There are still unanswered fields", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
// string adduser = String.Format(@"UPDATE INTO users_info (userID, Fname, Mname, Sname, Bdate, Position, username, password) VALUES (''{0}'',''{1}'', ''{2}'', ''{3}'',''{4}, ''{5}'', ''{6}'', ''{7}'')", UserID, userfname, usermname, usersname, userbdate, userpos, TBusername, TBpass);
const string connection = "Data source = abc; Database = PMP; Trusted_Connection = True;";
using (SqlConnection cnx = new SqlConnection(connection))
{
//SqlCommand command = new SqlCommand(adduser, cnx);
cnx.Open();
string addpay = (@"INSERT INTO table_OR ( ORdate, PayName, PayStypeId, PayStype, ORtotal, ORAsses)
VALUES ('" + paydate + "', '" +payname+ "', '" + stypeid + "', '" + stype + "', '" + paytotal + "','"+AssessBy+"')");
using (SqlCommand add_pay = new SqlCommand(addpay, cnx))
{
add_pay.ExecuteNonQuery();
}
MessageBox.Show("Payment successfully made!", "Successful!", MessageBoxButtons.OK);
// msgbox = MessageBox.Show("Edit another User?", "Edit Team", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (msgbox == System.Windows.Forms.DialogResult.Yes)
{
//text_reset();
PayName.Focus();
return;
}
else
this.Close();
cnx.Close();
}
}
}
catch (Exception err)
{
MessageBox.Show("Connection to database failed!" + err.Message);
//text_reset();
PayName.Focus();
return;
}
}
}
}