help in OleDbDataReader
-
i want to convert this vb.net code to c# code but i have problem with oledbdatareader i have missing code or i cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString. code with vb is working code: Dim con As New OleDbConnection Dim scom As New OleDbCommand Dim reader As OleDbDataReader While reader.Read Me.Label1.Text = reader.Item(0).ToString End While code with c# is not working missing line scom.Parameters.AddWithValue("@A", textBox1.Text); scom.CommandText = "Select Name from Table1 where (id=@A)"; scom.CommandType = CommandType.Text; scom.Connection = conn; OleDbDataReader reader = scom.ExecuteReader(); while (reader.Read()=true) { label1.Text= reader.; //probem is here coannot found item() }; property item(0) not found in C# code can any one help me
Ahmed hassan
-
i want to convert this vb.net code to c# code but i have problem with oledbdatareader i have missing code or i cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString. code with vb is working code: Dim con As New OleDbConnection Dim scom As New OleDbCommand Dim reader As OleDbDataReader While reader.Read Me.Label1.Text = reader.Item(0).ToString End While code with c# is not working missing line scom.Parameters.AddWithValue("@A", textBox1.Text); scom.CommandText = "Select Name from Table1 where (id=@A)"; scom.CommandType = CommandType.Text; scom.Connection = conn; OleDbDataReader reader = scom.ExecuteReader(); while (reader.Read()=true) { label1.Text= reader.; //probem is here coannot found item() }; property item(0) not found in C# code can any one help me
Ahmed hassan
hassanasp wrote:
cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString
If you're using indexers in vb they are in parenthesis but in c# they are in []. So have a try with
Label1.Text = reader.Item[0].ToString
hassanasp wrote:
while (reader.Read()=true)
In C# equality is
==
so:while (reader.Read()==true)
or
while (reader.Read())
The need to optimize rises from a bad design.My articles[^]
-
hassanasp wrote:
cannot convert this line into C# Me.Label1.Text = reader.Item(0).ToString
If you're using indexers in vb they are in parenthesis but in c# they are in []. So have a try with
Label1.Text = reader.Item[0].ToString
hassanasp wrote:
while (reader.Read()=true)
In C# equality is
==
so:while (reader.Read()==true)
or
while (reader.Read())
The need to optimize rises from a bad design.My articles[^]
-
the problem is when write(reader.)no property item found in C# but in vb is found label1.Text = reader.Item[0].ToString; Error 1 'System.Data.OleDb.OleDbDataReader' does not contain a definition for 'Item'
Ahmed hassan
Item property isn't language specific. It exists in the framework, not in the language see: OleDbDataReader.Item Property (Int32)[^]. One problem you have is that ToString is a method so it must have parenthesis so:
label1.Text = reader.Item[0].ToString();
or
label1.Text = reader[0].ToString();
The need to optimize rises from a bad design.My articles[^]