Hello I am trying to use OleDb to connect database but when i want to read data from there and use Read() command after that
cmd.Parameters.Add("@name", TextBox1.Text);
cmd.Parameters.Add("@password", TextBox2.Text);
cmd.ExecuteNonQuery();
System.Data.OleDb.OleDbDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string istifadeciAd = (string)rdr.GetString(1);
string istifadeciParol = (string)rdr.GetString(2);
}
in String istifadeciAd and istifadeciParol i got error for GetString because of IndexoutofRange. But don't we need to call GetString with column index?
you need to have more than 2 select columns in your select statement to get
rdr.GetString(2)
something like below
select id, istifadeciAd, istifadeciParol from Table1 where name =? and password =?
note that index is zero-based
So if you only select
istifadeciAd, istifadeciParol
columns you need to read it asAnd you don't need to cast the result to
string
, because it is returningstring
I think you need to change the parameters adding code as well,