How to configure SQL Server Authentication Mode

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 How to configure SQL Server for access over TCP/IP

 

 

 

 

 

 

 

 

 

 

 How to connect to SQL Server

 

 

 

 

 

http://www.connectionstrings.com

 

 

 

 

using System.Data.SqlClient;

 

        SqlConnection con;

        SqlCommand cmd;

     

 

        private void Select0()

        {

            listBox1.Items.Clear();

            string s1 = @"SELECT * FROM TABLEA WHERE f1=" + textBox1.Text;

            cmd = new SqlCommand(s1, con);

            SqlDataReader rd = cmd.ExecuteReader();

            if (rd.HasRows)

            {

                while (rd.Read())

                    listBox1.Items.Add(rd["f1"] + "   " + rd["f2"]);

            }

            rd.Close();

 

 

        }

 

 

        private void Select1()

        {

            listBox1.Items.Clear();

 

            string s1 = @"SELECT * FROM TABLEA WHERE f1 = @s2";

            cmd = new SqlCommand(s1, con);

            cmd.Parameters.AddWithValue("@s2", textBox1.Text);

 

            SqlDataReader rd = cmd.ExecuteReader();

            if (rd.HasRows)

            {

                while (rd.Read())

                    listBox1.Items.Add(rd["f1"] + "   " + rd["f2"]);

            }

            rd.Close();

        }

 

  

 

        private void Connect()

        {

            con = new SqlConnection(@"Data Source=B325\SQL2012EXPRESS;Initial Catalog=test2;Integrated Security=True");         

            con = new SqlConnection(@"Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes");

            con = new SqlConnection(@"Data Source=B325\SQL2012EXPRESS;Initial Catalog=test;User ID=krokodyl;Password=abc");

           

            con.Open();

            button2.Text = con.State.ToString();

           

        }

 

        private void Insert()

        {

           // string s1 = @"INSERT INTO TABLEB (g1,g2) VALUES (11,'abc')";

            string s1 = @"INSERT INTO TABLEB (g1,g2) VALUES ("+textBox2.Text+",'"+textBox3.Text+"')";

            cmd = new SqlCommand(s1, con);

            cmd.ExecuteNonQuery();

        }

 

        private void Select2()

        {

            listBox1.Items.Clear();

 

            string s1 = @"SELECT * FROM TABLEA; SELECT * FROM TABLEB";

            cmd = new SqlCommand(s1, con);

          

 

            SqlDataReader rd = cmd.ExecuteReader();

            do

            {

 

                while (rd.Read())

                {

                    string s3 = "";

                    for (int i = 0; i < rd.FieldCount; i++)

                    {

                        s3 += rd[i] + "    ";

                    }

                    listBox1.Items.Add(s3);

                }

 

            }

            while (rd.NextResult());

            rd.Close();

       

        }

 

        private void Update()

        {

            string s1 = @"Update TableA set f2='YYYYYYYY' Where f1<3";

            cmd = new SqlCommand(s1, con);

            int nr = cmd.ExecuteNonQuery();

            textBox1.Text = nr.ToString();

 

        }

 

        private void Delete()

        {

            string s1 = @"Delete from TableA Where f1<3";

            cmd = new SqlCommand(s1, con);

            int nr = cmd.ExecuteNonQuery();

            textBox1.Text = nr.ToString();

        }

   

        /*

         *

         *   CHAR(1000)

         *   NCHAR(1000)

         *   VARCHAR(1000)

         *   NVARCHAR(1000)

         *  

         */