please help...

asp.net , db , mysql Oshawa, Canada
  • 13 years ago

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <script language="VB" runat="server">

    sub Page_Load(sender as Object, e as EventArgs)

    Dim AutoValue
    dim Dscon as OleDbConnection
    dim SQL    as string
    dim DBCon1 as OleDbCommand

      Dscon = Server.CreateObject("ADODB.Connection")
      Dscon.Open "DSN=405d"
     
    SQL = "Select Max(cnum) as cnum From clientreg; "
        Set DBCon1 = Dscon.Execute(SQL)
     
        if not Isnull (DBCon1("cnum"))then
        AutoValue = DBCon1("cnum") + 1
        else
        Autovalue = "1001"
       
        end if
      end sub
    </script>

     

    ---please help... whats wrong with my syntax.. can anyone help me please. thanks.. 

  • 13 years ago

     I moved your code to a code behind page and reconstructed it to the following:

    Imports System.Data
    Imports System.Data.OleDb

    Partial Public Class WebForm1
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim AutoValue As Object
            Dim Dscon As OleDbConnection
            Dim DBCon1 As New OleDbCommand

            Dscon = New OleDbConnection
            Dscon.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=xxx;Data Source=yyy"
            Dscon.Open()

            DBCon1.Connection = Dscon
            DBCon1.CommandText = "Select Max(cnum) as cnum From clientreg; "
            AutoValue = DBCon1.ExecuteScalar()

            If AutoValue Is Nothing Then
                AutoValue = "1001"
            Else
                AutoValue = (CType(AutoValue, Integer) + 1).ToString()
            End If

            Response.Write(AutoValue)
            Response.Flush()
            Response.End()

        End Sub

    End Class

    Slightly different from your own. I'm sure you'll be able to determine where your code and mine differ.

    Jeo 

  • 13 years ago

    "thanks for your kindnes..."

    but, can you explain this syntax.. i don,t get it. i find it difficult cause i,m only just a beginner. in asp.net..

      Dscon.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=xxx;Data Source=yyy"

     Catalog=xxx;Data Source=yyy" -what do you mean by this?

    I'm just confuse, with this because i am using mysql as my database and DSN for the calling of my database..

    hope you'll not be irritated for me.. thanks in advance... 

     

     

  • 13 years ago

     Imports System.Data
    Imports System.Data.OleDb

    is this syntax same as syntax below?

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

     and what do you mean by:

    Partial Public Class WebForm1
        Inherits System.Web.UI.Page

    what is the purpose of this syntax...? 

    and do i need to put a syntax like

    <script runat=server>

    at the beginning and at the end of the syntax you have given to me?

     

     

     

     

  • 13 years ago

     [quote]

      Dscon.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=xxx;Data Source=yyy"

     Catalog=xxx;Data Source=yyy" -what do you mean by this?[/quote]

    this is simply syntax for connecting to a sql server database. I don;t run with mysql so just substitute your own dsn connection here.

    Joe 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann