PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2008 [RESOLVED] Quick question about MySQL in vb.net 2008-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] Quick question about MySQL in vb.net 2008

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Resolved [RESOLVED] Quick question about MySQL in vb.net 2008

    It it possible in vb.net to run a MySql command like you would do in MySQL
    or SQL?

    like insert and update statements and also to create a table in the db?

    If yes, how could I do this?

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Quick question about MySQL in vb.net 2008

    of course did you d/led the mysql .net connector?

    http://dev.mysql.com/downloads/connector/net/
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Quick question about MySQL in vb.net 2008

    Sorry I don't understand the term "d/led".
    If what you are asking if I have a MySQL client installed for vb, yes i have.

    Can you perhaps give me an example of code where you connect to a MySQL database and then , say insert a new row into a table.

    F.Y.I. ---->> This is the dataTable that I use.
    vb Code:
    1. Public Function ConnectMe(ByVal TableName As String) As DataTable
    2.         Dim conn As String = "Server=192.168.0.36;Port=3306;Database=wc;Uid=root;Pwd=123454321"
    3.         Dim cmd As String = "SELECT * FROM " & TableName
    4.         Dim ad As New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, conn)
    5.  
    6.         ad.GetFillParameters()
    7.         ad.Fill(topics)
    8.  
    9.         Dim dr As DataRow
    10.         Dim dt As DataTable
    11.         dt = topics.Tables(0)
    12.         intSetArray = dt.Rows.Count
    13.         ReDim names(intSetArray, 4)
    14.  
    15.         For Each dr In dt.Rows
    16.             names(i, 1) = dr(1) 'Username
    17.             names(i, 2) = dr(2) 'Password
    18.             names(i, 3) = dr(3) 'Active
    19.             names(i, 4) = dr(4) 'Accesslevel
    20.             i += 1
    21.         Next
    22.         topics.Dispose()
    23.         ConnectMe = topics.Tables(0)
    24.     End Function

    I don't use this datatable all the time, only for some aspects of my program. I also make use of the components in the toolbox

  4. #4

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Quick question about MySQL in vb.net 2008

    Sorry I don't understand the term "d/led".
    If what you are asking if I have a MySQL client installed for vb, yes i have.

    Can you perhaps give me an example of code where you connect to a MySQL database and then , say insert a new row into a table.

    F.Y.I. ---->> This is the dataTable that I use.
    vb Code:
    1. Public Function ConnectMe(ByVal TableName As String) As DataTable
    2.         Dim conn As String = "Server=192.168.0.36;Port=3306;Database=wc;Uid=root;Pwd=123454321"
    3.         Dim cmd As String = "SELECT * FROM " & TableName
    4.         Dim ad As New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, conn)
    5.  
    6.         ad.GetFillParameters()
    7.         ad.Fill(topics)
    8.  
    9.         Dim dr As DataRow
    10.         Dim dt As DataTable
    11.         dt = topics.Tables(0)
    12.         intSetArray = dt.Rows.Count
    13.         ReDim names(intSetArray, 4)
    14.  
    15.         For Each dr In dt.Rows
    16.             names(i, 1) = dr(1) 'Username
    17.             names(i, 2) = dr(2) 'Password
    18.             names(i, 3) = dr(3) 'Active
    19.             names(i, 4) = dr(4) 'Accesslevel
    20.             i += 1
    21.         Next
    22.         topics.Dispose()
    23.         ConnectMe = topics.Tables(0)
    24.     End Function

    I don't use this datatable all the time, only for some aspects of my program. I also make use of the components in the toolbox

  5. #5
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Quick question about MySQL in vb.net 2008

    this is how i connect to mysql db

    Code:
    Using connection as new MySqlConnection("ConnectionString")
    Using command as new MySqlCommand("YOUR QUERY",connection
    command.parameters.AddWithValue("MyParam",1)
    connection.open()
    commend.ExecuteScalaer/ExecuteNonQuery/ExecuteReader (or whatever)
    end using
    End Using
    i wrote it from the top of my head since i don't have the code here i also use C# so you might need some tweaking
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: [RESOLVED] Quick question about MySQL in vb.net 2008

    Hey,

    It's a small point, but in my opinion, your method is poorly named. You have a method called ConnectMe, but in actual fact, that method is connecting to the database, executing a command, and returning a result.

    You may want to think about refactoring that.

    Gary

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width