Results 1 to 3 of 3

Thread: GetSize DataBase SQL

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    61

    GetSize DataBase SQL

    Hello every one
    Please how to make for display size global of DataBse SQL in TextBox1
    I find this code in internet but i have not managed it in my Form
    Code:
    Dim GetSize As New SqlCommand("SELECT DB_NAME(database_id) AS DBName,Name AS Logical_Name, Physical_Name,(size*8)/1024 SizeMB FROM sys.master_files WHERE DB_NAME(database_id) = 'Customers'", con)
            GetSize.ExecuteScalar()
    Sincerely
    ABE

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: GetSize DataBase SQL

    ExecuteScalar will only return the first field of the first row... so in this case it's returning the first DBName that it finds. But even then that's thrown away since you don't even put it into a variable.
    Try using .Execute and putting the results into a DataTable, and then you'll get all of the rows (even if there's only one) and all of the columns...


    OR...

    You can change the SQL to only return the size calculation and nothing else, and keep the .ExecuteScalar and catch the results into a variable for display on your form.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2018
    Posts
    61

    Re: GetSize DataBase SQL

    Thank you very much Techgnome for the explanation
    Please
    How to display in datagridview the database names with these sizes
    3 columns in datagrid for example: ID DBName Size
    Code:
    Dim CONNE As New SqlConnection("Server=ABIDINE;Database=PHARMADATA;Integrated Security=false;user id=sa;password=**********;")
    Dim SQLTable As String = "Select * From TABLE1"
            SQLTable = "Select * from TABLE1  where ID like '%" & TextBox1.Text & "%'"
            InfoTable.Clear()
    Dim InfoAdapter As New SqlDataAdapter(SQLTable, CONNE)
            InfoAdapter.Fill(InfoTable)
      DataGridView1.DataSource = InfoTable
    Sincerely
    ABE

Posting Permissions

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



Click Here to Expand Forum to Full Width