"Arjen" <bo*****@hotmail.comwrote in message
news:f4**********@news2.zwoll1.ov.home.nl...
Hi,
This are the lines I have now:
SqlDataSource1.SelectCommand = "SELECT TOP (1) RangeId FROM myTable";
SqlDataSource1.SelectParameters.Add(new Parameter("RangeId",
TypeCode.Int32));
int rangeId = ...
How do I get the result from the database in the variable? I tried a lot
of samples on the internet but could not find the solution.
Why don't you use a DataReader?
MyDataReader[1] // equals field two of the fields being pulled back in the
recordset record.
Or you can use MyDataReader['caseid'] // if field 0 is the record's key.
You might have to go through a Convert to set a database field to the proper
variable type.
So in your case, the Reader is only to read one record and hit EOF.
SqlConnection MyConnection = new SqlConnection(@"Data Source=(local);
Initial Catalog = CaseManager; Integrated Security=true");
MyConnection.Open();
SqlCommand MyCommand = new SqlCommand("SELECT * FROM CaseInfo",
MyConnection);
SqlDataReader MyDataReader =
MyCommand.ExecuteReader(CommandBehavior.CloseConne ction);
while (MyDataReader.Read())
{
Console.WriteLine(MyDataReader[0] + " " + MyDataReader[1]);
}
MyConnection.Close();