I am trying to search and save record but when i search the system goes back to the first invno number yet i wanted it to go to the next invno number
Please help i wanted to search and get the selected record to be insert into a table
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Invnogenerator.aspx.vb" Inherits="SulaSignar.Invnogenerator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td>Invno</td>
<td>
<asp:TextBox ID="Invno" runat="server" Width="42px"></asp:TextBox>
</td>
<td>Admno</td>
<td>
<asp:TextBox ID="admno" runat="server"></asp:TextBox>
</td>
<td>Name</td>
<td>
<asp:TextBox ID="Names" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Search" />
</td>
<td> </td>
</tr>
<tr>
<td colspan="4"> </td>
<td>
<asp:Button ID="Button2" runat="server" Text="SaveRecord" />
</td>
<td colspan="2"> </td>
<td> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
Imports System.Data
Imports System.Linq
Imports System.Configuration
Imports System.Data.SqlClient
Public Class Invnogenerator
Inherits System.Web.UI.Page
Dim bk, TRCODE, khold, Pusername, shifted, hold, hold2, hold3, hold4, hold6 As String
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Redirect("~/Forms/StudentSearch2000.aspx")
End Sub
Dim m, j As Double
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dataread()
End Sub
Private Sub dataread()
Dim strConnString As String = ConfigurationManager.ConnectionStrings("TRIALSIGNARConnectionString").ConnectionString
Using con As SqlConnection = New SqlConnection(strConnString)
Using cmd As SqlCommand = New SqlCommand()
cmd.CommandText = "SELECT * From maxbooked"
cmd.Connection = con
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
If sdr.HasRows Then
sdr.Read()
j = sdr("bookedinv").ToString()
Else
'Message to show does not have values.
j = 0
End If
con.Close()
End Using
End Using
Dim strConnStringb As String = ConfigurationManager.ConnectionStrings("TRIALSIGNARConnectionString").ConnectionString
Using con As SqlConnection = New SqlConnection(strConnStringb)
Using cmd As SqlCommand = New SqlCommand()
cmd.CommandText = "SELECT * From Clienttemp"
cmd.Connection = con
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
If Not sdr.HasRows Then
sdr.Read()
' j = sdr("bookedinv").ToString()
TRCODE = 1
Me.Invno.Text = TRCODE
Else
Dim strConnString2p As String = ConfigurationManager.ConnectionStrings("TRIALSIGNARConnectionString").ConnectionString
Using conn As SqlConnection = New SqlConnection(strConnString2p)
Using cmdn As SqlCommand = New SqlCommand()
cmdn.CommandText = "SELECT * From maxinvoicetemp"
cmdn.Connection = conn
conn.Open()
Dim sdrt As SqlDataReader = cmd.ExecuteReader()
If sdrt.HasRows Then
sdrt.Read()
If String.IsNullOrEmpty(sdrt("maximum").ToString()) Then
TRCODE = 1
Me.Invno.Text = TRCODE
Else
m = sdrt("maximum").ToString()
TRCODE = m + 1
Using conk As SqlConnection = New SqlConnection(strConnString)
Using cmdk As SqlCommand = New SqlCommand()
cmdk.CommandText = "SELECT * From CLIENTtemp"
cmdk.Connection = conk
conk.Open()
Dim sdrk As SqlDataReader = cmdk.ExecuteReader()
If sdrk.HasRows Then
sdrk.Read()
m = sdrk("maximum").ToString()
TRCODE = m + 1
If TRCODE <= j Then
Me.Invno.Text = j + 1
Else
TRCODE = 1
Me.Invno.Text = TRCODE
End If
End If
End Using
End Using
End If
End If
con.Close()
End Using
End Using
End If
con.Close()
End Using
End Using
If j = 0 Then
Insert(Me.Invno.Text)
Else
Insert(Me.Invno.Text)
End If
End Sub
Public Sub Insert(name As String)
Dim constr As String = ConfigurationManager.ConnectionStrings("TRIALSIGNARConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("INSERT INTO maxbooked (bookedinv) VALUES (@Name)")
cmd.Parameters.AddWithValue("@Name", name)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Sub
End Class