Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Object to execute SQL statements in Visual Studio
    primarykey
    data
    text
    <p>I apologize if my question is simple, but I have done a lot of looking on the Internet and I am having trouble finding a solution.</p> <p>I have a database connected to Visual Studio where I used the "Connect to Database..." wizard to establish the connection. In the Server Explorer in Visual Studio, I see I have a Data Connection called "newreptDBtest.accdb", and a Server named Mandrew.</p> <p>Basically I would like to execute SQL statements on this database when clicking a button. So I have a button on a form, and it has the following code:</p> <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sqlconn As New SqlConnection sqlconn.ConnectionString = "server=Mandrew;Initial Catalog=newreptDBtest.accdb" Try sqlconn.Open() Catch ex As Exception MessageBox.Show("Error on connection") End Try If sqlconn.State = 1 Then MessageBox.Show("Success!") End If End Sub </code></pre> <p>In General Declarations, I have:</p> <pre><code>Imports System.Data.SqlClient </code></pre> <p>Perhaps because it's not a SQL database? I'm not sure. Either way, I have not been able to achieve the "Success!" from the MessageBox. Once I've gotten that, I'm sure I can figure out how to create SQL statements to return certain rows or single pieces of information.</p> <p>In the newreptDBtest, the table I'd like to be executing queries on is called newrept, and the connection string to the database is: </p> <pre><code>"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Andrew\Documents\newreptDBtest.accdb" </code></pre> <p>tl;dr:</p> <p>How do I use an object (such as a button) to execute SQL queries on a table inside a database already connected to my project? </p> <p>Thanks in advance, SuperXero</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload