After the query execution the result I need to take is UserNames part.
I’m gettting an error: Cannot apply indexing with [] to an expression of type ‘method group’
public class ProcessInput
{
string connectionString = (string)ConfigurationSettings.AppSettings["myConString"];
private string msg_arr;
string username = null;
private void MooseSeenInput(string MobileNo, string Date, string odd, params Array[] msg_arr)
{
SqlConnection conn = new SqlConnection(myConString);
conn.Open();
SqlCommand com = new SqlCommand("SELECT * FROM Users as users WHERE UserName=@UserName AND State!='1' AND State!='4'", conn);
com.Parameters.AddWithValue("@UserName", UserName);
// com.ExecuteNonQuery();
using (SqlDataReader reader = com.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
String UserNames = (reader.Read["users"]);
}
}
}
}
}
Error occurred at line:
String UserNames = (reader.Read["users"]);
Your error is a compiler error as you were trying to apply index syntax onto a method call, which in C# involves brackets.
The
SqlDataReaderdoes expose an indexer, but it is on the reader itself, not a method member:This is how I tend to style this code:
Note that I ask the reader for the ordinal prior to iterating an unknown number of records. This is good for two reasons: