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
Solved

Run Query in VB.Net

Posted on 2004-04-20
7
207 Views
Last Modified: 2010-04-24
hi,

I am writing a windows application and need to run an update or append query from a button on my form.

I have two table, tblEmp1, tblEmp2 , both has 3 similar fields, EmpID, EmpName and EmpDept,

1. I Need to Update tblEmp2 from tblEmp1, but with a click of a button on my form

2. Same as above but need to run appned query,

both of my tables are on Access database,

Please give me hard code and detials how to do it.

thankx
0
Comment
Question by:nibirkhan
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:malharone
ID: 10872454
       Dim conn As New SqlClient.SqlConnection("YOUR_CONNECTION_STRING")

        Dim sc As SqlClient.SqlCommand = conn.CreateCommand()
        sc.CommandText = "update your_table set column1='hello', column2='world'"

        sc.ExecuteNonQuery()
0
 
LVL 2

Author Comment

by:nibirkhan
ID: 10873618
Sorry, My tables are in Access database not on SQl server
0
 
LVL 9

Expert Comment

by:malharone
ID: 10873667

        Dim conn As New System.Data.OleDb.OleDbConnection("YOUR_CONNECTION_STRING")
        Dim sc As OleDb.OleDbCommand = conn.CreateCommand()
        sc.CommandText = "update your_table set column1='hello', column2='world'"

        sc.ExecuteNonQuery()
0
 
LVL 2

Author Comment

by:nibirkhan
ID: 10880683
nope, I guess it's not the thing I am wanting, why do I have to insert value inside my query, I want to Merge those two tables with a click of a button without having repeated value, that's why I guess I need an unoin query...

thanks
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 11094326
INSERT INTO tblEmp1
SELECT tblEmp2.*
FROM tblEmp2
WHERE EmpID Not In (Select EmpID From tblEmp1

Bob
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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