[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

C#.net - datareader issue

not sure...I am getting errors at this line:

sql_username = dataReader["USERNAME"].ToString;

try
        {

            //Dim dl_stores_files As New List(Of String)
            //Dim client_stores_files As New List(Of String)
            SqlDataReader dataReader = default(SqlDataReader);

            int x = 0;

            string sqlConnection = null;

            using (SqlConnection sqlConn = new SqlConnection())
            {



                // sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=xx;User Id=;Password=;"

                sqlConnection = "Data Source=xx.xx.xx.xx;Initial Catalog=xxx;Trusted_connection=true;";
                sqlConn.ConnectionString = sqlConnection;

                string SQLstring = "SELECT * FROM customer_login WHERE USERNAME = '" + userName + "' AND PASSWORD = '" + passWord + "'";


                // Dim dataReader As SqlDataReader
                sqlConn.Open();
                using (SqlCommand command = new SqlCommand(SQLstring, sqlConn))
                {
                    dataReader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

                    if (dataReader.HasRows)
                    {

                        while (dataReader.Read())
                        {

                            sql_username = dataReader["USERNAME"].ToString;
                            sql_password = dataReader("PASSWORD").ToString;
                            TC_id = dataReader("TC_ID").ToString;
                            Session("email_address") = dataReader("email_address").ToString;

                            Session("SessionUsername") = sql_username;
                            Session("sessionPassword") = sql_password;
                            Session("sessionTC_ID") = TC_id;

                            Session("MULTI_CLIENT_ID") = dataReader("MULTI_CLIENT_ID").ToString;

                        }

                    }
                    else
                    {
                    }
                    dataReader.Close();
                    sqlConn.Close();
                }
            }

Open in new window

0
GlobaLevel
Asked:
GlobaLevel
  • 2
1 Solution
 
viralypatelCommented:
ToString is a method ... use it with brackets i.e. ToString();


sql_username = dataReader["USERNAME"].ToString();
sql_password = dataReader("PASSWORD").ToString();

Open in new window

0
 
Easwaran ParamasivamCommented:
Use [] instead of () while getting PASSWORD. Below code should work.
sql_username = (string) dataReader["USERNAME"];
sql_password = (string) dataReader["PASSWORD"];

Open in new window

0
 
Easwaran ParamasivamCommented:
Please note that that is applicable for all fields in the datareader.

Session("key") should be changed as Sessiong["key"] as well.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now