Results 1 to 22 of 22

Thread: [RESOLVED] [VB2010] - my 1st database

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Resolved [RESOLVED] [VB2010] - my 1st database

    i'm learning Vb2010 data base from: http://www.vbtutor.net/index.php/vis...010-lesson-30/
    wasn't easy undertand that i must:
    - create mdf file from 'New Item' and choose 'Service-based Data Base';
    - when we click on these item, on Left Side, we create a new table;
    - after we create a new table, we click on right mouse button for show the menu and choose 'Show Table Data'. and here we can add table index elements.
    but my problem, now is connect my database
    Code:
    Public MyCn As New SqlConnection
    MyCn.ConnectionString = "Data Source=lenovo-4903350b\mssmlbiz; AttachDbFilename=C:\ManutencaoDeAutomoveis\ManutencaoDeAutomoveis\Database1.mdf; " & _
                                    "User Instance=True;Integrated Security=SSPI"
    i get these 2 errors:
    "A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
    A first chance exception of type 'System.TypeInitializationException' occurred in ManutencaoDeAutomoveis.exe"

    please anyone can advice me?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: [VB2010] - my 1st database

    The tutorial specifically says ....

    * You need to change the reference to the SQL server (lenovo-4903350b\mssmlbiz) as well as the path to database file Test.mdf .
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by dunfiddlin View Post
    The tutorial specifically says ....
    the file i did, because i know what to do, but i don't know the SQL Server
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [VB2010] - my 1st database

    When creating connection strings to SQL Server, you can use "(local)" or "." to refer to the local machine without having to specify its actual name. That has the advantage of your not having to know the current machine name and it will also continue to work if you move the project or application to another machine. If you're using SQL Server Express then your instance name is almost certainly going to be "SQLEXPRESS". As such, you Data Source value in the connection string should probably be ".\SQLEXPRESS".

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by jmcilhinney View Post
    When creating connection strings to SQL Server, you can use "(local)" or "." to refer to the local machine without having to specify its actual name. That has the advantage of your not having to know the current machine name and it will also continue to work if you move the project or application to another machine. If you're using SQL Server Express then your instance name is almost certainly going to be "SQLEXPRESS". As such, you Data Source value in the connection string should probably be ".\SQLEXPRESS".
    you have right. thanks.
    but my error was on these line:

    Code:
    Private m_DataRow As DataRow = m_DataTable.Rows(0)
    i comment before '=' and now works perfect.
    so let me ask 2 things:
    1 - if the error was that line, why tell me the error was that line that i give you?
    2 - when we write '.'(dot) a listbox is showed for we select an item. we use, normaly, enter key for select it. that item it's selected but a new line is add in same time. but it's bored can i avoid, in these case, the enter a new line?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: [VB2010] - my 1st database

    1) I don't think we know quite enough to be able to answer that question fully. It appears that m_DataTable has no rows, in which case Rows(0) is out of range. That's the easy answer, but it certainly isn't sufficient, because the real question is WHY was m_DataTable empty, which depends on the steps taken to fill m_DataTable. It is possibly as simple as the query returning no rows, but it could be considerably more complex than that, too, so we'd have to see the code that filled the table if you want a more complete answer.

    2) This question I do not understand.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by Shaggy Hiker View Post
    1) I don't think we know quite enough to be able to answer that question fully. It appears that m_DataTable has no rows, in which case Rows(0) is out of range. That's the easy answer, but it certainly isn't sufficient, because the real question is WHY was m_DataTable empty, which depends on the steps taken to fill m_DataTable. It is possibly as simple as the query returning no rows, but it could be considerably more complex than that, too, so we'd have to see the code that filled the table if you want a more complete answer.

    2) This question I do not understand.
    1) thanks.. it's ok.
    2) thing in these way: you write 'label1.' we you wrote the dot, a listbox with label properties\methods is showed. normaly i use the enter\return key(#13 of ascci table) for showe the lisbox item. the word is printed, but make a new line too can i avoid these new line?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: [VB2010] - my 1st database

    Oh, I think I understand you. You are talking about the Intellisense box that shows the properties\methods (and more, too). Enter doesn't work the same for me as it does for you, but try using the Tab key, instead, and see how that works for you.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by Shaggy Hiker View Post
    Oh, I think I understand you. You are talking about the Intellisense box that shows the properties\methods (and more, too). Enter doesn't work the same for me as it does for you, but try using the Tab key, instead, and see how that works for you.
    yes.. if i use the space key, the word is writed too but with a space. i belive the tab do the same ideia
    VB6 2D Sprite control

    To live is difficult, but we do it.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: [VB2010] - my 1st database

    It doesn't for me. However, there does appear to be some difference in the operation between you and I, so we have the environments set up differently in some way.
    My usual boring signature: Nothing

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [VB2010] - my 1st database

    if you're typing out a long class name, such as System.Windows.Forms.DialogResult:

    Name:  11-01-2014_02.05.50.jpg
Views: 233
Size:  25.4 KB

    if you type System. the intellisense window pops up + if you highlight Windows, you can select Windows + pop up another intellisense window by typing another .

  12. #12

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    thanks to all
    another question: can i do 2 diferents programs(exe) that share the same mdf database file?
    (i'm build the normal program and i will build a hidden program for just test what we have on data base file)
    Last edited by joaquim; Jan 21st, 2014 at 03:05 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  13. #13
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: [VB2010] - my 1st database

    Quote Originally Posted by joaquim View Post
    thanks to all
    another question: can i do 2 diferents programs(exe) that share the same mdf database file?
    Of course. The database is just another resource like any image, text file etc. You may ruin into some issues if you're running both programs at the same time with concurrency but we can cross that bridge if you come to it.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  14. #14

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by dunfiddlin View Post
    Of course. The database is just another resource like any image, text file etc. You may ruin into some issues if you're running both programs at the same time with concurrency but we can cross that bridge if you come to it.
    so i must recreate another project and add it a data base file?
    or theres another simple way?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  15. #15
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: [VB2010] - my 1st database

    Er .. don't really understand that question. You have the database already in place. You can connect to it from any project using the Connection string you have in the current project.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  16. #16

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by dunfiddlin View Post
    Er .. don't really understand that question. You have the database already in place. You can connect to it from any project using the Connection string you have in the current project.
    i add a new project, now i have a Sollution. but how can i set what project to run?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  17. #17

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    for set the startup project(on menus): Project -> Set as startup project
    (i think that we can set a shortcut key for these tool )
    now i have added an empty project and for works, we need go to the project properties and add a Reference: System.Data... and see my tested code:
    Code:
    Imports System.Data.SqlClient
    Imports System.Data
    
    Module main
    
        Private m_rowPosition As Integer = 0
        Private cnADONetConnection As New SqlConnection()
        Private m_cn As New SqlConnection()
        Private m_DA As SqlDataAdapter
        Private m_CB As SqlCommandBuilder
        Private m_DataTable As New DataTable
        Private m_DataRow As DataRow
    
        Sub Main()
            m_cn.ConnectionString = "Data Source=.\SQLEXPRESS; AttachDbFilename = " & _
    "C:\ManutencaoDeAutomoveis\ManutencaoDeAutomoveis\Database1.mdf; " & _
    "Integrated Security=True; Connect Timeout=30;" & "User Instance=True"
            m_cn.Open()
            m_DA = New SqlDataAdapter("Select * From Manutencao", m_cn)
            m_CB = New SqlCommandBuilder(m_DA)
            m_DA.Fill(m_DataTable)
            MsgBox(m_DataTable.Rows(0)("IDMarcaModelo").ToString())
    
        End Sub
    
    End Module
    (readers these is a test program and not completed )
    the message box show me what i need... very cool... thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  18. #18

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    let me ask anotherthing: the user will not see the printer view. so what you advice me?
    i never used printed with VB2010, can you give me something simple for i start, please?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  19. #19
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [VB2010] - my 1st database

    Quote Originally Posted by joaquim View Post
    let me ask anotherthing: the user will not see the printer view. so what you advice me?
    i never used printed with VB2010, can you give me something simple for i start, please?
    My advice is to read the title of this thread and ask yourself whether it ha anything to do with printing. If the answer is "no" then ant questions on printing should be asked in a different thread; one dedicated to that topic.

  20. #20

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by jmcilhinney View Post
    My advice is to read the title of this thread and ask yourself whether it ha anything to do with printing. If the answer is "no" then ant questions on printing should be asked in a different thread; one dedicated to that topic.
    ok..thanks i will do it now
    before close these thread... please see my Sub Main() code. i was reading from a tutorial, but i have 1 question: do i need close or dispose that variables?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  21. #21
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [VB2010] - my 1st database

    Quote Originally Posted by joaquim View Post
    ok..thanks i will do it now
    before close these thread... please see my Sub Main() code. i was reading from a tutorial, but i have 1 question: do i need close or dispose that variables?
    You don't close or dispose variables. You might close or dispose the objects that those variables refer to. Do those objects have Close or Dispose methods? If so then you need to call them and if not then you don't.

  22. #22

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: [VB2010] - my 1st database

    Quote Originally Posted by jmcilhinney View Post
    You don't close or dispose variables. You might close or dispose the objects that those variables refer to. Do those objects have Close or Dispose methods? If so then you need to call them and if not then you don't.
    thanks for that advice.. thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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