Transaction no
Hi,
I am trying to generate a transaction number for every transaction I enter in my database, so I
Use the following code to select the last number to which I plan to add a "ONE"
qlConnection cn = new SqlConnection("Data Source=KATOTO-PC;Initial Catalog =thyfarm;User ID=sa;Password=Kyozi");
string sql = ("select MAX(transno) from prodtntransno");
SqlCommand cmd = new SqlCommand(sql, cn);
cn.Open();
string s1 = cmd.ExecuteScalar().ToString();
textBox4.Text = s1.ToString();
This code will retrieve the last transaction number for example 11111112 to which I will add a "1"
Generating the next number which should be 11111113. Now this is where my problem begins, below the above code I have placed the code below
int a = System.Convert.ToInt32(textBox4.Text);
int b = System.Convert.ToInt32(textBox5.Text);
int c = (a + b);
textBox3.Text = c.ToString();
this code is intended to add a "1" which is set as the text of textbox5.text, however when I run I get an ERROR!! "Overflow Exception was unhandled – Value was either too large or too small for an int32 "
any help will be highly appreciated.

VulpesPosted Jan 5, 2012, 6:07 AM
Marvin kakuruPosted Jan 9, 2012, 4:19 AM
Satyapriya NayakPosted Jan 5, 2012, 6:43 AM
Try this...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void btn_insert_Click(object sender, EventArgs e)
{
Int32 a = System.Convert.ToInt32(t1.Text);
Int32 b = System.Convert.ToInt32(t2.Text);
Int32 c = (a + b);
t3.Text = c.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
str = "select MAX(transno) from prodtntransno";
com = new SqlCommand(str, con);
con.Open();
com = new SqlCommand(str, con);
t1.Text = com.ExecuteScalar().ToString();
con.Close();
}
}
Thanks