Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB Visual-Studio VB.NET
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 20: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
0 Sergey Alexandrovich Kryukov 9,455
1 OriginalGriff 8,295
2 Peter Leow 4,839
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,301


Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100