Exemplo n.º 1
0
        static public void readFunc()
        {
            SqlConnection con = DoConneection.funcConnection();

            try
            {
                con.Open();
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT [ROLL_NO],[SUBJECT],[MARKS] FROM [dbo].[MARKS] ");
                String sql = sb.ToString();
                using (SqlCommand command = new SqlCommand(sql, con))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine("{0} {1} {2}", reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2));
                        }
                        Console.ReadLine();
                    }
                }
                con.Close();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Exemplo n.º 2
0
        static public void insertFunc()
        {
            SqlConnection con = DoConneection.funcConnection();
            StringBuilder sb  = new StringBuilder();

            sb.Append("INSERT INTO [dbo].[MARKS] ([ROLL_NO],[SUBJECT],[MARKS]) VALUES(4,'Arts',99)");
            String sql = sb.ToString();

            using (SqlCommand command = new SqlCommand(sql, con))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    con.Open();
                    while (reader.Read())
                    {
                        Console.WriteLine("{0} {1} {2}", reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2));
                    }
                    Console.ReadLine();
                }
            }
            con.Close();
        }
Exemplo n.º 3
0
        static public void updateFunc()
        {
            SqlConnection con = DoConneection.funcConnection();
            StringBuilder sb  = new StringBuilder();

            sb.Append("UPDATE FROM [dbo].[MARKS] SET SUBJECT='MATHS' where ROLL_NO=1");
            String sql = sb.ToString();

            using (SqlCommand command = new SqlCommand(sql, con))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    con.Open();
                    while (reader.Read())
                    {
                        Console.WriteLine("{0} {1} {2}", reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2));
                    }
                    Console.ReadLine();
                }
            }
            con.Close();
        }