[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

adding rows to new database with visual basic

Posted on 2011-02-21
13
Medium Priority
?
1,452 Views
Last Modified: 2012-05-11
Hello People

I have just created a new database called database1.sdf with just two records.

I did this using the IDE in Visual Studio.

But I now want to add a few hundred records that reside in a file to this new database, and I do not even know how to begin to do this.

I am competent in Visual Basic, but I am clueless about databases.

How should I begin? Where should I look?

Thank you

Karl

Capture.PNG
0
Comment
Question by:KarlTheHopeless
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34948630
you can use "inser into" command for instert record

Sample

insert into BasicTable(Title,FirstName) Values('Mr.','Kalpesh')

0
 

Author Comment

by:KarlTheHopeless
ID: 34948707
I don't think that even gets me to first base.

Don't I need to connect to the database, or something? - before I can do anything.
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 200 total points
ID: 34948723
Open SSMS.
Connect to your server.
Expand databases.
Expand your database.
Expand Tables.
Right click on your table.
Select 'Edit Top 200 rows'
Enter new records.
Save the table
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:KarlTheHopeless
ID: 34948769
That doesn't seem appropriate really.

I need to read a very big file of records and then chop each RECORD into the various FIELDS of the new database.

My problem is that I do not know how to OPEN this database and Read/Write to it using Visual Basic.
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34948915
0
 

Author Comment

by:KarlTheHopeless
ID: 34948951
Hi Kalpesh

I tried this, but it failed to connect, ...

Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.ConnectionString = "Data Source = C:\Users\karl\Documents\Visual Studio 2010\Projects\Pupils\Pupils\Database1.sdf"
        con.Open()
        cmd.Connection = con
     
0
 

Author Comment

by:KarlTheHopeless
ID: 34948961
I got this error message ...

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

But I do not know what to do about it.
0
 
LVL 16

Accepted Solution

by:
Kalpesh Chhatrala earned 1800 total points
ID: 34949006
Go To Server Explorer ;
right Click on Database1.sdf connection Properties

Copy Value of connection String from Properties window

and use this value for connection

0
 

Assisted Solution

by:KarlTheHopeless
KarlTheHopeless earned 0 total points
ID: 34949099
That's exactly what I did.

The pathway is correct.
0
 

Author Comment

by:KarlTheHopeless
ID: 34949114
Ha. I'm almost there, having found the code below elsewhere.

My *only* problem now seems to be with the INSERT bit in the following code.

I've obviously misunderstood how it works,

.....

  Dim con As New System.Data.SqlServerCe.SqlCeConnection("Data Source=C:\Users\karl\Documents\Visual Studio 2010\Projects\Pupils\Pupils\Database1.sdf")
       
        con.Open()
       
        Dim cmd As System.Data.SqlServerCe.SqlCeCommand

        'Create an instance of SqlCeDataReader
        Dim dtr As System.Data.SqlServerCe.SqlCeDataReader

        'INSERT
        cmd = New System.Data.SqlServerCe.SqlCeCommand("INSERT INTO BasicTable (ParentID,FirstName,SecondName) VALUES (3,john,smith)", con)
        cmd.ExecuteNonQuery()

        'Retrieve data from BasicTable
        cmd = New System.Data.SqlServerCe.SqlCeCommand("SELECT FirstName FROM BasicTable", con)
        dtr = cmd.ExecuteReader()

        'Read and display the data
        While dtr.Read()
            MsgBox(dtr("FirstName"))
        End While
        'Close the DataReader
        dtr.Close()

        'Close the database connection
        con.Close()
0
 

Author Comment

by:KarlTheHopeless
ID: 34949176
Got it.

The apostrophes were missing.
0
 

Author Closing Comment

by:KarlTheHopeless
ID: 34986631
Thank you.
0
 
LVL 1

Expert Comment

by:MarkThomasLee
ID: 37091927
kalpesh2804
Thank you for your response to this thread.  I'm not having the same issue, but did find the link to datasets, collections, and such very helpful.  I'm an old Visual Studio 6 developer C++, VB. Didn't do any .net stuff, just ADO, and ODBC.  I found the .net / collections & dataset article very helpful at getting my head around DATASETS & COLLECTIONS. I can really see the value.

Thanx again
Mark
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question