Dear friends,
I want to display form number on form load and save it in the table starting from 1 and incrementing it by 1 and also check for duplicate form number should not get saved in table.. starting from 1 to 2,3,4,5...................... Its should be saved like this in table...
How can i do it plzz help
Loading

Mayur GujrathiRank #666 · 3.6K reputationPosted May 30, 2011, 2:34 AM EDT
Kavita elaborate more it is possible to save anything on form load still refer this query SELECT Max(ISNULL(id, 0)+1) FROM tablename; check every time on form load when this value is present in database using exist keywordPosted May 30, 2011, 2:39 AM EDT
Can't use Identity column in database ?
Kavita B135 reputationPosted May 30, 2011, 2:40 AM EDT
I have a read only textbox which on form load displays a number starting from 1 which is saved in table... next time for next record textbox should display 2 which again will be saved in table as next record and 3 and 4 and so on
Posted May 30, 2011, 2:44 AM EDT
For this you can use, DataTable has the Primarykey option. So, there you can't store duplicate value.
Once the first value is saved into the database table, then you can increate the datatable value and show into the textbox.
Hoep this helps you.
Kavita B135 reputationPosted May 30, 2011, 2:45 AM EDT
Yes u got it.. But how do i do it?
Posted May 30, 2011, 3:12 AM EDT
private void button1_Click(object sender, EventArgs e)
{ DataRow dr = dt.Rows[0];
dr.BeginEdit();
dr["Sno"] = Convert.ToInt32(dr["Sno"]) + 1;
dt.EndInit();
dt.AcceptChanges();
textBox1.Text = dt.Rows[0].ItemArray[0].ToString();
}
DataTable dt = new DataTable();
private void Form2_Load(object sender, EventArgs e){
dt.Columns.Add(new DataColumn("Sno",Type.GetType("System.Int32")));
DataRow dr = dt.NewRow();
dr["Sno"] = 1;
dt.Rows.Add(dr);
dt.AcceptChanges();
textBox1.Text = dt.Rows[0].ItemArray[0].ToString();}
Hope this sample helps you.
Kavita B135 reputationPosted May 31, 2011, 2:48 AM EDT
I want the admission no in this format.. SS/11-12/06 which is 1st 2 are characters next is the academic year and next is the month....Can someone help
Mayur GujrathiRank #666 · 3.6K reputationPosted May 31, 2011, 3:14 AM EDT
DECLARE
@ALPHA_VAL CHAR(1) , @INT_VAL VARCHAR(1000)
DECLARE @VAL INT =97, @VAL1 INT =1
WHILE @VAL <= 122
BEGIN
SET @VAL1=1
WHILE @VAL1 < 1000
BEGIN
SET @ALPHA_VAL = CHAR(@VAL)
SET @INT_VAL = CONVERT(CHAR,@VAL1)
SET @INT_VAL= @ALPHA_VAL + @INT_VAL
PRINT @INT_VAL
SET @VAL1 =@VAL1+1
END
SET
@VAL=@VAL+1
END
Posted May 31, 2011, 3:26 AM EDT
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = dt.Rows[0];
dr.BeginEdit();
dr["Sno"] = Convert.ToInt32(dr["Sno"]) + 1;
dt.EndInit();
dt.AcceptChanges();
textBox1.Text = dt.Rows[0].ItemArray[0].ToString() + dt.Rows[0].ItemArray[1].ToString();
}DataTable dt = new DataTable();
private void Form2_Load(object sender, EventArgs e)
{
dt.Columns.Add(
dt.Columns.Add(
dr[
"Prefix"] = "SS/11-12/"; //Based on your logic get the Prefix details here.dr["Sno"] = 1;
dt.Rows.Add(dr);
dt.AcceptChanges();
textBox1.Text = dt.Rows[0].ItemArray[0].ToString() + dt.Rows[0].ItemArray[1].ToString();
}
Hope this helps you.
new DataColumn("Prefix", Type.GetType("System.String")));dt.Columns.Add(new DataColumn("Sno",Type.GetType("System.Int32")));
DataRow dr = dt.NewRow();