Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error '' Only assignment, call, increment, decrement, and new object expressions can be used as a statement '', on line 116 column 30

Tags:

c#

.net

sql

Well I am a newbie, and am trying to compile a .NET application but I am encountering many errors with the recompilation, this error in particular:

Only assignment, call, increment, decrement, and new objects expressions can be used as a statement

On line 116 where this is located { SqlDataReader CS;1;0000; } what do you suggest?

namespace ProBall
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.IO;
    using System.Net;
    using System.Runtime.InteropServices;

    public class DataManager
    {
        public static List<string> barcodes = new List<string>();
        private string connStr;
        private string queryStr;
        public static bool queueMessage;
        public static bool serverStatus = false;

        public DataManager()
        {
        }

        public DataManager(string connStr, string queryStr)
        {
            this.connStr = connStr;
            this.queryStr = queryStr;
        }

        public static IPAddress FindIPAddress(bool localPreference)
        {
            return FindIPAddress(Dns.GetHostEntry(Dns.GetHostName()), localPreference);
        }

        public static IPAddress FindIPAddress(IPHostEntry host, bool localPreference)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (host.AddressList.Length != 1)
            {
                foreach (IPAddress address in host.AddressList)
                {
                    bool local = IsLocal(address);
                    if (local && localPreference)
                    {
                        return address;
                    }
                    if (!(local || localPreference))
                    {
                        return address;
                    }
                }
            }
            return host.AddressList[0];
        }

        public string FormatDates(string date)
        {
            string tmpDate = date;
            try
            {
                string[] nDate = null;
                string day = string.Empty;
                string month = string.Empty;
                string year = string.Empty;
                if (tmpDate.Contains("/"))
                {
                    nDate = date.Split(new char[] { '/' });
                    day = nDate[0];
                    month = nDate[1];
                    year = nDate[2].Split(new char[] { ' ' })[0];
                    return (month + "/" + day + "/" + year);
                }
                if (tmpDate.Contains("-"))
                {
                    tmpDate = date.Split(new char[] { ' ' })[0];
                }
            }
            catch (Exception er)
            {
                this.LogError(er.Message, "GENERIC");
            }
            return tmpDate;
        }

        public string GetUserName(string tableName = "employees")
        {
            return this.ReadValue(string.Concat(new object[] { "select id from ", tableName, " where CurrentlyLoggedIn = 1 and LastLoginStation = '", ReturnHostName(), "' and LastLoginStationIP = '", FindIPAddress(true), "'" }), ConfigurationSettings.AppSettings["kcam"]);
        }

        public static bool IsLocal(IPAddress address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            byte[] addr = address.GetAddressBytes();
            return (((addr[0] == 10) || ((addr[0] == 0xc0) && (addr[1] == 0xa8))) || (((addr[0] == 0xac) && (addr[1] >= 0x10)) && (addr[1] <= 0x1f)));
        }

        public void LogError(string message, string logType = "GENERIC")
        {
            StreamWriter ftmp = new StreamWriter(@"c:\coopnet\server\debug.txt", true);
            ftmp.WriteLine(message);
            ftmp.Close();
        }

        public bool LogOffUser(string tableName = "employees")
        {
            return this.SaveEntityData(string.Concat(new object[] { "update ", tableName, " set CurrentlyLoggedIn = 0  where LastLoginStation = '", ReturnHostName(), "' and LastLoginStationIP = '", FindIPAddress(true), "'" }), ConfigurationSettings.AppSettings["kcam"]);
        }

        public SqlDataReader ReadData()
        {
            SqlDataReader CS;1;0000;
            using (SqlConnection conn = new SqlConnection(this.connStr))
            {
                using (SqlCommand cmd = new SqlCommand(this.queryStr, conn))
                {
                    conn.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        CS;1;0000 = reader;
                    }
                }
            }
            ; return CS; 1; 0000;
        }

        public bool ReadData(string query)
        {
            bool status = false;
            this.queryStr = query;
            using (SqlConnection conn = new SqlConnection(this.connStr))
            {
                using (SqlCommand cmd = new SqlCommand(this.queryStr, conn))
                {
                    conn.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            status = true;
                        }
                    }
                    return status;
                }
            }
        }

        public bool ReadData(string query, string connection)
        {
            bool status = false;
            using (SqlConnection conn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    conn.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            status = true;
                        }
                    }
                    return status;
                }
            }
        }

        public string ReadValue(string query, string connectionStr)
        {
            string value = string.Empty;
            this.queryStr = query;
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionStr))
                {
                    using (SqlCommand cmd = new SqlCommand(this.queryStr, conn))
                    {
                        conn.Open();
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();
                                return reader[0].ToString();
                            }
                        }
                    }
                    return value;
                }
            }
            catch (Exception)
            {
                return value;
            }
            return value;
        }

        public static string ReturnHostName()
        {
            return Dns.GetHostName();
        }

        public bool SaveData()
        {
            try
            {
                bool status = false;
                using (SqlConnection conn = new SqlConnection(this.connStr))
                {
                    using (SqlCommand cmd = new SqlCommand(this.queryStr, conn))
                    {
                        conn.Open();
                        cmd.ExecuteReader();
                        status = true;
                    }
                }
                return status;
            }
            catch (Exception se)
            {
                this.LogError(se.Message, "GENERIC");
                return false;
            }
        }

        public bool SaveEntityData(string query, string connectionString)
        {
            try
            {
                Func<string, bool> performQuery = delegate (string querySql) {
                    this.connStr = connectionString;
                    this.queryStr = querySql;
                    return this.SaveData();
                };
                return performQuery(query);
            }
            catch (Exception e)
            {
                this.LogError("Error: " + e.Message, "GENERIC");
                return false;
            }
        }
    }
}
like image 687
peter muya Avatar asked Nov 27 '25 15:11

peter muya


2 Answers

It looks like you are trying to use the value CS;1;0000; as a variable name, but this is invalid per the Language Spec §2.4.2 Identifiers. You cannot use semi-colons in variable names, as these have a special meaning as the end of a statement. If you re-name that variable to CS10000 or CS_1_0000 that should solve your problem.

like image 123
goric Avatar answered Nov 29 '25 04:11

goric


Have a look at your public SqlDataReader ReadData() method. It has issues with semicolons.

SqlDataReader CS;1;0000; is not legal syntax. You can't name a variable CS;1;10000; Call it CS1000 and repeat through the method.

like image 31
mcalex Avatar answered Nov 29 '25 04:11

mcalex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!