How set db and read it?

namreg

New member
Joined
Jun 6, 2018
Messages
3
Programming Experience
Beginner
Hello, I am really a beginner on C# development. But, sometimes i like to play around with C# and try to develop stuff.

I have sql express 2014. Visual C# 2017 Community Version.
I created a database through SQL Management Studio in my local computer.
The name of the DB is ReleasesLogin and has a table called Login and two fields:Login, password.

With C# how do i connect into that DB and populate the the DB ?

Bear with me, i am not 100% proficient with C#. Thanks for your help,

I have created the project already in C#
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,375
Location
Sydney, Australia
Programming Experience
10+
I suggest that you make use of the tutorial link in my signature below. You should probably read it in its entirety but, specifically, the third-last chapter deals with databases. We can help with specific issues along the way but, to be honest, this question is a bit broad because there are many places that you can learn the basics of data access in C#.

One point to note is that that tutorial suggests creating the data file as part of your project. I would suggest that you just follow the tutorial as written first of all. You can then look at variations, e.g. connecting to Microsoft SQL Server instead of a Microsoft SQL Server Data File. Again, we can help with those specific details but you may gather enough from the tutorial to work through them yourself.
 

namreg

New member
Joined
Jun 6, 2018
Messages
3
Programming Experience
Beginner
Thank you very much. I will start reading the tutorial.
 

Casper Beckett

New member
Joined
Aug 27, 2019
Messages
1
Programming Experience
Beginner
Hello, I am really a beginner on C# development. But, sometimes i like to play around with C# and try to develop stuff.

I have sql express 2014. Visual C# 2017 Community Version.
I created a database through SQL Management Studio in my local computer.
The name of the DB is ReleasesLogin and has a table called Login and two fields:Login, password.

With C# how do i connect into that DB and populate the the DB ?

Bear with me, i am not 100% proficient with C#. Thanks for your help,

I have created the project already in C#
here is my code that will help you
C#:
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 Login
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void metroButton2_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=10.0.0.24,4256;Initial Catalog=LoginDB;Persist Security Info=True;User ID=server;Password=0000;");
            SqlDataAdapter sda = new SqlDataAdapter("SELECT Count(*) From Login where Username='" + metroTextBox1.Text + "' and Password ='" + metroTextBox2.Text + "'",con);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.Hide();
                Main ss = new Main();
                ss.Show();
                metroTextBox1.Text = ss.label11.Text;



            }
            else
            {
                this.panel1.Visible = true;
                

            }

        }

        private void metroButton1_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void metroLabel8_Click(object sender, EventArgs e)
        {
            this.Hide();

            Admin_Login admin = new Admin_Login();

            admin.Show();
        }
    }
}
 
Last edited by a moderator:
Top Bottom