9 Replies - 294 Views - Last Post: 20 March 2019 - 05:32 AM Rate Topic: -----

#1 hiran1800   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 06-November 10

variable string data merge in class command in vb.net

Posted 18 March 2019 - 09:58 PM

I create many cls command in order to connect variable database.
so, I set up clscommand001 , clscommand002....003...
If i decare string 001,002,003.... and i need to merge this string with the obj (clscommand ) , is it possible ?

sample :

Dim cn As New ClsCommand
Dim sql As String

how to put string after clsCommand
like this : Dim cn As New ClsCommand_001

because sometime i can select other...002,003...
I try to use concatenate "&" but still cannot



 Sub GetSupplierNM()

        Dim cn As New ClsCommand
        Dim sql As String

        sql = "Select supplierID,supname From Tb_Supplier"
        sql = sql & " WHERE supplierID = '" & txtSupID.Text & "'"

        cn.ReadData(sql)

        Dim i As Integer = 0
        If cn.dr.HasRows <> 0 Then

            Do While cn.dr.Read

                 txtSupNM.Text = cn.dr.Item("supname").ToString

            Loop

        Else
            txtSupNM.Text = ""

        End If

        cn.closedb()

    End Sub




I already try to decare ;
Dim a as string = _002
Dim cn As New ClsCommand & a ..............still cannot.

Is This A Good Question/Topic? 0
  • +

Replies To: variable string data merge in class command in vb.net

#2 maceysoftware   User is online

  • Member Title
  • member icon

Reputation: 370
  • View blog
  • Posts: 1,586
  • Joined: 07-September 13

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 01:03 AM

First off naming your classes 001, 002, 003 is a poor design choice. You should name them according to what they do. If you got a command which selects user call it something that describes that it will be selecting the users.

In terms of defining a variable type from a concatenated string, you won't be able to do that how you are attempting to do it, you could use reflection so that might be worth researching, but you would have to interact with the object through reflection as well, in my eyes not really worth it.

This post has been edited by maceysoftware: 19 March 2019 - 01:03 AM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,950
  • Joined: 12-December 12

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 01:51 AM

Naming objects 001, 002, strongly suggests that they should be stored in a collection (a List) of some kind.
Was This Post Helpful? 0
  • +
  • -

#4 hiran1800   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 06-November 10

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 02:10 AM

i don't know how to do another method in order to give user select database from our list at login form.
and i decision to make 10 class command after user select from 001 - 010. but it's cannot do.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,950
  • Joined: 12-December 12

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 02:55 AM

I do not understand your post.

Posting some code for your ClsCommand might give us a better idea of what you are trying to achieve.
Was This Post Helpful? 0
  • +
  • -

#6 hiran1800   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 06-November 10

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 03:31 AM

ClsCommand_001

Imports System.Data
Imports System.IO
Imports System.Data.OleDb

Public Class ClsCommand_000

    Public dr As OleDbDataReader
    Dim cn As New OleDbConnection(Strcon0)
    Dim cm As OleDbCommand = cn.CreateCommand
    Dim tr As OleDbTransaction
    Public TR_Start As Boolean = False
    Public ErrorStarus As Boolean = False
    Public RecordProcess As Integer = 0
    Public ds As New DataSet
    Public da As New OleDbDataAdapter

    Sub New()
        If cn.State = ConnectionState.Open Then cn.Close()
        cn.Open()

    End Sub
    Sub closedb()
        cn.Close()
    End Sub




clsCommand_002

Imports System.Data
Imports System.IO
Imports System.Data.OleDb

Public Class ClsCommand_002

    Public dr As OleDbDataReader
    Dim cn As New OleDbConnection(Strcon2)
    Dim cm As OleDbCommand = cn.CreateCommand
    Dim tr As OleDbTransaction
    Public TR_Start As Boolean = False
    Public ErrorStarus As Boolean = False
    Public RecordProcess As Integer = 0
    Public ds As New DataSet
    Public da As New OleDbDataAdapter

    Sub New()
        If cn.State = ConnectionState.Open Then cn.Close()
        cn.Open()

    End Sub
    Sub closedb()
        cn.Close()
    End Sub



This post has been edited by andrewsw: 19 March 2019 - 03:48 AM
Reason for edit:: fixed botched code tags

Was This Post Helpful? 0
  • +
  • -

#7 hiran1800   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 06-November 10

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 03:42 AM

I meaning that i have 10 clscommand ( clscommand_000 until clscommand_010 ) which is connect in different name of database.
if i make login form for user , and give the user can choice to select which database between 001 - 010 and after , when user use some form to connection database , It can be connect the correct clscommand_xxx

example : user choice 001 from text box in login from , and after they can connect clscommand_001 also.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6776
  • View blog
  • Posts: 27,950
  • Joined: 12-December 12

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 03:56 AM

Wow. That is not maintainable, flexible code. At the very least you only need a single class with a different connection string.

I am (mildly) curious why a user would be free to select between 10 different databases?

Anyway, if you choose to persist with code like that, then you might as well just use a switch statement to choose between the 10 classes. Fill your boots.
Was This Post Helpful? 0
  • +
  • -

#9 DarenR   User is offline

  • D.I.C Lover

Reputation: 601
  • View blog
  • Posts: 3,932
  • Joined: 12-January 10

Re: variable string data merge in class command in vb.net

Posted 19 March 2019 - 09:52 AM

just make 1 db connection class and call that class with your input
Was This Post Helpful? 0
  • +
  • -

#10 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 209
  • View blog
  • Posts: 1,187
  • Joined: 05-December 13

Re: variable string data merge in class command in vb.net

Posted 20 March 2019 - 05:32 AM

Why do you have multiple classes with the same code? Create a new instance of your current class for reuse.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1