1 Replies - 1137 Views - Last Post: 08 April 2011 - 07:12 AM Rate Topic: -----

#1 stelios12323  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-April 11

How To Access A Database Using SQL

Posted 07 April 2011 - 08:05 PM

Hello everybody, I am new to the database access so please forgive me for these question and if the seem basic.
I have been following some examples how to access a database using the sql commands.
However I do not quite understand firstly how to create a database "FreezerTemps", and what information I am required to add in the SqlConnection in order to get access to it.

I create the database using the Microsoft Visual C# 2010 Express, this is located in the directory of the code itself. I believe the Microsoft SQL Server 2008 is running as well but did not change anything there, as I am very new to this concept.

I attach the code I am using below.

Thank you for reading my question and code.

Kind regards,
Stelios.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WebDatabase
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            SqlConnection cs = new SqlConnection("Data Source=nemesisfc; Initial Catalog=FreezerTemps; Integrated Security=TRUE");
            cs.Open();
            MessageBox.Show(cs.State.ToString());
            cs.Close();


         }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: How To Access A Database Using SQL

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: How To Access A Database Using SQL

Posted 08 April 2011 - 07:12 AM

Honestly you would do well reading up in a book. It's hard to explain the entirety of database concepts and db interactions in a thread post, but I'll try and sum up a few things.

Quote

I do not quite understand firstly how to create a database "FreezerTemps"

Where is your database? If you are using SQL Server (and you installed it) then open up the SQL Management tool and navigate to your "localhost". There look for the menu option about creating a database instance, and that instance you can create a table. That table would be "FreezerTemps". You would add columns to that table.


Quote

information I am required to add in the SqlConnection in order to get access to it

You would add information as in password, user name, starting table, etc.

http://www.connectionstrings.com can help out with the nitty gritty.


Quote

I create the database using the Microsoft Visual C# 2010 Express

It sounds like you created a file - like with MS Access. This has no bearing on your MSSQL install. You need to pick which one you want to use.

Check the tutorials above. There are ones in VB.NEt and C# relating to database interactions. Read up on those. Get a book... learn about databases in a more structured way.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1