Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how do i retrive the data from one cell in the sql database?

how do i retrive the data from one cell in the sql database?

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasequestionasp-net
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neodeaths
    wrote on last edited by
    #1

    hi guys i would like to retrive the data of One cell of the sql database's table i already know the command will be like this: select age from kids where nric = 'sss' this command statement would retrive only 1 result however i dont know the sysntex to use this command statment with in asp.net (c# coding side) could anyone show me how it is done pls?

    G N 2 Replies Last reply
    0
    • N neodeaths

      hi guys i would like to retrive the data of One cell of the sql database's table i already know the command will be like this: select age from kids where nric = 'sss' this command statement would retrive only 1 result however i dont know the sysntex to use this command statment with in asp.net (c# coding side) could anyone show me how it is done pls?

      G Offline
      G Offline
      gauthee
      wrote on last edited by
      #2

      sqlconnection conn = new sqlconnection(path of the connection); sqlcommand cmd = new sqlcomand("your query", connection); string result; result=cmd.executescalar();

      Gautham

      1 Reply Last reply
      0
      • N neodeaths

        hi guys i would like to retrive the data of One cell of the sql database's table i already know the command will be like this: select age from kids where nric = 'sss' this command statement would retrive only 1 result however i dont know the sysntex to use this command statment with in asp.net (c# coding side) could anyone show me how it is done pls?

        N Offline
        N Offline
        neodeaths
        wrote on last edited by
        #3

        it says Error 51 The type or namespace name 'sqlconnection' could not be found (are you missing a using directive or an assembly reference?)

        T V 2 Replies Last reply
        0
        • N neodeaths

          it says Error 51 The type or namespace name 'sqlconnection' could not be found (are you missing a using directive or an assembly reference?)

          T Offline
          T Offline
          Tirthadip
          wrote on last edited by
          #4

          be sure to import System.Data.SqlClient NameSpace

          Tirtha Miles to go before I sleep

          N 1 Reply Last reply
          0
          • T Tirthadip

            be sure to import System.Data.SqlClient NameSpace

            Tirtha Miles to go before I sleep

            N Offline
            N Offline
            neodeaths
            wrote on last edited by
            #5

            i already added using System.Data.SqlClient; if this is not correct pls kindly describe what i shld do pls

            N 1 Reply Last reply
            0
            • N neodeaths

              i already added using System.Data.SqlClient; if this is not correct pls kindly describe what i shld do pls

              N Offline
              N Offline
              Nicejith
              wrote on last edited by
              #6

              hi .. here is some code for connecting to database.. i think this would help you.. make necessary changes.. this is just to show you how we can connect to the db.. put connection string in web.config file using System; using System.Data; using System.Configuration; using System.Data.SqlClient; public class dbClass { private SqlConnection con; private SqlCommand com; private SqlDataReader dr; private SqlDataAdapter da; private DataSet ds; public dbClass() { con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conString"].ToString()); } /// /// Open an Sql connection. /// /// sqlconnection public SqlConnection GetConnection() { try { if (con.State == ConnectionState.Open) { con.Close(); } con.Open(); } catch (Exception ex) { string err = ex.Message.ToString(); } return con; } /// /// Executes a query with SqlDataAdapter /// /// sql query /// DataTable public DataTable GetAdapter(string sql) { try { com = new SqlCommand(sql, GetConnection()); com.CommandTimeout = 0; da = new SqlDataAdapter(com); ds = new DataSet(); da.Fill(ds); return ds.Tables[0]; } finally { con.Close(); } }

              1 Reply Last reply
              0
              • N neodeaths

                it says Error 51 The type or namespace name 'sqlconnection' could not be found (are you missing a using directive or an assembly reference?)

                V Offline
                V Offline
                Vinay Dornala
                wrote on last edited by
                #7

                hi u can see this code and do it string strCmd="select age from kids where nirc='sss'"; Sqlcommand cmd =new sqlCommand(strCmd,con); cmd.CommandType=CommandType.Text; con.open(); DataReader dr=cmd.ExecuteReader(); while(dr.read) { // code to populate data example u want to populate to combo box then u can writecode like this cmdAge.add.item(dr.GetValues[1]); } try with this code i hope u will come out of the problem tell me confirm once ok

                N 1 Reply Last reply
                0
                • V Vinay Dornala

                  hi u can see this code and do it string strCmd="select age from kids where nirc='sss'"; Sqlcommand cmd =new sqlCommand(strCmd,con); cmd.CommandType=CommandType.Text; con.open(); DataReader dr=cmd.ExecuteReader(); while(dr.read) { // code to populate data example u want to populate to combo box then u can writecode like this cmdAge.add.item(dr.GetValues[1]); } try with this code i hope u will come out of the problem tell me confirm once ok

                  N Offline
                  N Offline
                  neodeaths
                  wrote on last edited by
                  #8

                  actually in my web.config i already have an connection string called HASDBConnectionString1 what i basically need is ONE value(int) while using the HASDBConnectionString1 connectionstring name in my web.config my query is queryed by the key column so it always retrun only 1 value i am using asp.net2 (2005) and sql server 2005

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups