How to: connectionString
?
Hopefully a simple question, but I am too new to Visual Basic
to understand :
http://msdn.microsoft.com/en-us/library/d7469at0.aspx...
I am writing an app in VB
and trying to connect it to a "Local Database" / "Dataset".
I received help earlier today to get the code listed below and it appears it will work just fine, except I have no idea how to connect my application to my dataset. From the reading I have been doing, it seems the connectionString would be to connect it to a database that was created with SQL Server. ???
On my VB Windows Form Application, I simply did "Add New Item" then "Local Database" and it asked me what type of database model and I selected "Dataset".
I only have two tables and just need to be able to connect to them. Here is the code or at least the idea of what I would like to do. Please help
Using sqlCon = New SqlConnection(connectionString)
sqlCon.Open()
Dim sqlText = "UPDATE appTable SET clickCount + 1 " & _
"WHERE appName = @name"
Dim cmd = New SqlCommand(sqlText, sqlCon)
cmd.Parameters.AddWithValue("@name", appName)
cmd.ExecuteNonQuery()
End Using
I am so sorry for this poorly phrased question, I have been reading and trying to learn this for too long and have frustrated myself. I come from Python with a lot less syntax and "rules" and I feel I could be way farther on this project and to be stuck on simply connecting to the "database" has me beyond frustrated :/
Thanks for assistance in advance.
answer : There is an App.config file in my Solution Explorer with the connectionString Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\gadgetDatabase.mdf;Integrated Security=True
This question is related to
sql
vb.net
visual-studio-2012
The Connection String Which We Are Assigning from server side will be same as that From Web config File. The Catalog: Means To Database it is followed by Username and Password And DataClient The New sql connection establishes The connection to sql server by using the credentials in the connection string.. Then it is followed by sql command which retrives the required data in the dataset and then we assing them to required variables or controls to get the required task done
May it will help for u. U should use (localdb).
LocalDB automatic instance
Server=(localdb)\v11.0;Integrated Security=true;
LocalDB automatic instance with specific data file
Server=(localdb)\v11.0;Integrated Security=true;
AttachDbFileName=C:\MyFolder\MyData.mdf;
Set the connection string in your config file:
<connectionStrings>
<add name="ConnString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\gadgetDatabase.mdf;Integrated Security=True" />
</connectionStrings>
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.IO
Imports System.Configuration
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Dim cn As New SqlConnection(connectionString)
Dim cmd As New SqlCommand
Dim dr As SqlDataAdapter
Standard Security:
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
Trusted Connection:
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
will be glad if it helps.
Regards.
if (reader.HasRows)
{
while (reader.Read())
{
comboBox1.Items.Add(reader.GetString(0));
}
}
reader.Close();
MySqlDataReader reader1 = cmd1.ExecuteReader();
if (reader1.HasRows)
{
while (reader1.Read())
{
listBox1.Items.Add(reader1.GetString(0));
}
}
reader1.Close();
Try
Dim connectionString AS String = "Server=my_server;Database=name_of_db;User Id=user_name;Password=my_password"
And replace my_server, name_of_db, user_name and my_password with your values.
then Using sqlCon = New SqlConnection(connectionString)
should work
also I think your SQL is wrong, it should be SET clickCount= clickCount + 1
I think.
And on a general note, the page you link to has a link called Connection String which shows you how to do this.
Source: Stackoverflow.com