Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Dear Coders,
 
I had a simple programming to fetch data from sql server and put serial number automatically.
 
Form name - Form1
 
Serial No - Textbox1.text
 
Project ID - Textbox2.text
 
Project Name - Combobox1.selected value
 
But When I run the program it actually works in a way. The Problem is when i select the project for the first time it is putting the value as "1" and if I select the Project for the Second time it fetches data from sql and add one to the max of serial number. I have Even Given the Full code Below. Please help.
 
Imports System.Data.SqlClient
 
Public Class Form1
 
    Dim con As New SqlConnection
    Dim myconstring As String = "Data Source=ETA-TESTSRVR;Initial Catalog=Procurement;Integrated Security=True"
 
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 
        TextBox2.Text = ComboBox1.SelectedValue
        con.ConnectionString = myconstring
        Dim da As New SqlDataAdapter("SELECT max(sl_no)+1 as max FROM e1 where project_id='" + TextBox2.Text + "'", con)
        Dim dt As New DataTable
        da.Fill(dt)
        If TextBox1.Text = "" Then
            TextBox1.Text = 1
        Else
            TextBox1.Text = dt.Rows(0).Item("max").ToString
        End If
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        'TODO: This line of code loads data into the 'ProcurementDataSet.Project' table. You can move, or remove it, as needed.
        Me.ProjectTableAdapter.Fill(Me.ProcurementDataSet.Project)
 
    End Sub
End Class
Posted 14-Nov-12 19:46pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Solved This Myself..
 
Just Changed the Code Like this.
 
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 
       TextBox2.Text = ComboBox1.SelectedValue
       con.ConnectionString = myconstring
       Dim da As New SqlDataAdapter("SELECT max(sl_no)+1 as max FROM e1 where project_id='" + TextBox2.Text + "'", con)
       Dim dt As New DataTable
       da.Fill(dt)
       TextBox1.Text = dt.Rows(0).Item("max").ToString
       If TextBox1.Text = "" Then
           TextBox1.Text = 1
       End If
 
   End Sub
 
Anyways Thanks for your Help Coders..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 Tadit Dash 350
2 Manas Bhardwaj 319
3 Sergey Alexandrovich Kryukov 250
4 Peter Leow 245
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,716
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid