Пример #1
0
        static public void update()
        {
            SqlConnection co = Dconnection.deepakConnection();

            try
            {
                co.Open();
                StringBuilder sb = new StringBuilder();
                sb.Append("update [dbo].[netpractice] set data='dpk' where id=1");
                //sb.Append("FROM [SalesLT].[ProductCategory] pc ");
                //sb.Append("JOIN [SalesLT].[Product] p ");
                //sb.Append("ON pc.productcategoryid = p.productcategoryid;");
                String sql = sb.ToString();
                using (SqlCommand command = new SqlCommand(sql, co))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine("{0} {1}", reader.GetInt32(0), reader.GetString(1));
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Пример #2
0
        public static void insert()
        {
            SqlConnection co = Dconnection.deepakConnection();

            try
            {
                co.Open();
                StringBuilder sb = new StringBuilder();
                sb.Append("insert into [dbo].[netpractice] (id,data,location) values (8,'Deepak','sdlklkds'); ");
                //sb.Append("FROM [SalesLT].[ProductCategory] pc ");
                //sb.Append("JOIN [SalesLT].[Product] p ");
                //sb.Append("ON pc.productcategoryid = p.productcategoryid;");
                String sql = sb.ToString();
                using (SqlCommand command = new SqlCommand(sql, co))
                {
                    command.ExecuteNonQuery();
                    Console.WriteLine("Inserted !!");
                }
                Console.ReadLine();
                co.Close();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.ToString());
            }
        }