-
Jan 9th, 2014, 11:05 AM
#1
Thread Starter
PowerPoster
[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?
-
Jan 9th, 2014, 11:11 AM
#2
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!
-
Jan 9th, 2014, 11:13 AM
#3
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by dunfiddlin
The tutorial specifically says ....
the file i did, because i know what to do, but i don't know the SQL Server
-
Jan 10th, 2014, 12:09 AM
#4
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".
-
Jan 10th, 2014, 04:13 PM
#5
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by jmcilhinney
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?
-
Jan 10th, 2014, 04:21 PM
#6
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
-
Jan 10th, 2014, 04:27 PM
#7
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by Shaggy Hiker
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?
-
Jan 10th, 2014, 04:33 PM
#8
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
-
Jan 10th, 2014, 04:42 PM
#9
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by Shaggy Hiker
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
-
Jan 10th, 2014, 08:19 PM
#10
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
-
Jan 10th, 2014, 09:15 PM
#11
Re: [VB2010] - my 1st database
if you're typing out a long class name, such as System.Windows.Forms.DialogResult:
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 .
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 21st, 2014, 02:58 PM
#12
Thread Starter
PowerPoster
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.
-
Jan 21st, 2014, 03:06 PM
#13
Re: [VB2010] - my 1st database
Originally Posted by joaquim
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!
-
Jan 21st, 2014, 03:09 PM
#14
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by dunfiddlin
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?
-
Jan 21st, 2014, 03:15 PM
#15
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!
-
Jan 21st, 2014, 03:27 PM
#16
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by dunfiddlin
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?
-
Jan 21st, 2014, 03:43 PM
#17
Thread Starter
PowerPoster
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
-
Jan 21st, 2014, 03:47 PM
#18
Thread Starter
PowerPoster
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?
-
Jan 21st, 2014, 05:04 PM
#19
Re: [VB2010] - my 1st database
Originally Posted by joaquim
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.
-
Jan 21st, 2014, 05:10 PM
#20
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by jmcilhinney
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?
-
Jan 21st, 2014, 05:16 PM
#21
Re: [VB2010] - my 1st database
Originally Posted by joaquim
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.
-
Jan 21st, 2014, 05:20 PM
#22
Thread Starter
PowerPoster
Re: [VB2010] - my 1st database
Originally Posted by jmcilhinney
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|