Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Connection string problem (http://www.go4expert.com/forums/connection-string-problem-t20011/)

Carlos 6Nov2009 15:53

Connection string problem
 
Hi! i wanna access sql database through my C# console app. but it don't produce output.
plz see my code
Code:

static void Main(string[] args)
        {
            string source =@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWIND.mdf;Integrated Security=True;User Instance=True";



            string query = "Select * from Customers";
            SqlConnection conn = new SqlConnection(source);
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(query, conn);

                int rowaffected = cmd.ExecuteNonQuery();

                if (rowaffected != 0)
                    Console.Write(rowaffected.ToString());////output
                else
                    Console.Write("No row affected");
            }
            catch (SqlException e)
            {
                Console.Write(e.ToString());
            }
            finally
            {
                conn.Close();
            }
           
         

        }

I have placed a database Northwind.mdf in C:\SQL Server 2000 Sample Databases folder, and i have added a dataconnection to this through server Explorer.

Please tell me where i am wrong ?? why it don't give output.


All times are GMT +5.5. The time now is 03:28.