ADO.NET 應用程式範例

       Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( Request.ApplicationPath);
        string connectionString=rootWebConfig.ConnectionStrings.ConnectionStrings["ConnectionString"].ConnectionString;

        string queryString ="SELECT * FROM [test];";
        using (SqlConnection connection =
            new SqlConnection(connectionString))
        {
            SqlCommand command = connection.CreateCommand();
            command.CommandText = queryString;

            try
            {
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();
                reader.Read(); //取得第1筆資料
              
                 int a=(int)reader[0];
                 Label1.Text = a.ToString();
                 Label2.Text = (string)reader[1];                   
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
   

相關連結:

http://msdn.microsoft.com/zh-tw/library/dw70f090(VS.80).aspx

ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.cht/dv_vwdcon/html/5b374087-bd7b-42ee-aced-2152088481a3.htm

 

arrow
arrow
    全站熱搜

    wuminfajoy 發表在 痞客邦 留言(1) 人氣()