954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

miscellaneous - vb 2008

Could anyone help me with these;
1. Create a new line in vb 2008 (endl in c++)
2. Steps in updating a database when the database resides into another computer
(for my client/server application)

Thanks averyone, hope you could do something for this! my system is almost done...

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

Mark, you will have to give us a bit more info here.

What do you mean by - Create a new line in vb 2008, a new line of code, a string etc?

What kind of database are you using, Sql, MySql, Access etc?

In the mean while, have a look at the following link to getting your app connected to the database - http://www.connectionstrings.com/ , choose your database and go through the connection string that will suite you.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Ok, I'm sorry for the insufficient information. Well, new line whose equivalent in C++ is "endl". When this code is executed, the following string will be printed to the next line of the screen during run-time.
And then my database is MS Access 2007 (compatible with vb 2008)

I hope that was sufficient already,
Thanks!
Please, be an angel to me!

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

Use vbCrLf - new line (line feed character).

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Alright! That's what I was so looking forward. CRLF! How about for my database?

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 
Alright! That's what I was so looking forward. CRLF! How about for my database?
Dim sql = "update tableName set colName1=@p2 where colName2=@p1"
        cmd.CommandText = sql
        cmd.Connection = cn
        cmd.Parameters.AddWithValue("@p2", "Hello" & vbCrLf & "World")
        cmd.Parameters.AddWithValue("@p1", my_id)
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

I can't figure this out.

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

I can't figure this out. What's in the code ADATAPOST?

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 
I can't figure this out. What's in the code ADATAPOST?


I guess you will have to put in a bit more effort and try it on your own. Read the MSDN documentation or books related to the Database API and do some experimentation.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

There are several ways to connect to a database on another computer.
If the database is on a Microsoft SQL Server, then you have the System.Data.SqlClient namespace.
If the database is an Access database, then you have the System.Data.OleDb namespace.

So, assuming the the database is an MS SQL Server then this is one way to connect to it.

Imports System.Data.SqlClient

Private Sub UpdateDatabase()
   Dim con As New SqlConnection("Data Source=computer2; Initial Catalog=thedatabase; User ID=billybob; Password=hamburger;")
   Dim com As SqlCommand = Nothing

   Try
      con.Open()
      com = New SqlCommand("UPDATE table SET col2=@p2 WHERE col1=@p1", con)
      com.Parameters.AddWithValue("@p1", 365)
      com.Parameters.AddWithValue("@p2", "Hello World")
      com.ExecuteNonQuery()
      con.Close()
   Catch ex As Exception
      If con.State = ConnectionState.Open Then
         con.Close()
      End If
   End Try
End Sub


For an Access database, the equivalent would be this:

Imports System.Data.OleDb

Private Sub UpdateDatabase()
   'MS Access 97-2003
   Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\computer2\sharedfolder\mydatabase.mdb;User Id=admin;Password=;")
   'MS Access 2007
   Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\computer2\sharedfolder\myAccess2007file.accdb;Persist Security Info=False;")

   Dim com As OleDbCommand = Nothing

   Try
      con.Open()
      com = New OleDbCommand("UPDATE table SET col2=@p2 WHERE col1=@p1", con)
      com.Parameters.AddWithValue("@p1", 365)
      com.Parameters.AddWithValue("@p2", "Hello World")
      com.ExecuteNonQuery()
      con.Close()
   Catch ex As Exception
      If con.State = ConnectionState.Open Then
         con.Close()
      End If
   End Try
End Sub
Oxiegen
Master Poster
715 posts since Jun 2006
Reputation Points: 87
Solved Threads: 141
 

Thank you so much guys, well, at least this community has helped me in my thesis. Special thanks to adatapost and oxiegen whoever you are. until next time!

markdean.expres
Junior Poster
152 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You