HungOver and not thinking straight

Don
Joined
5 Oct 2005
Posts
11,242
Location
Liverpool
I have this SQL query... dont know what I'm doing wrong would like some help...

public static int GetBookingInsertID()
{
string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
System.Data.SqlClient.SqlConnection sqlconnection = new System.Data.SqlClient.SqlConnection(connectionString);

string queryString = "SELECT MAX [book].[PriKey] FROM [book]";
System.Data.SqlClient.SqlCommand sqlcommand = new System.Data.SqlClient.SqlCommand(queryString, sqlconnection);

System.Data.SqlClient.SqlDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter(sqlcommand);
System.Data.DataSet dataSet = new System.Data.DataSet();
//dataAdapter.Fill(dataSet);
dataAdapter.Fill(dataSet);


return dataSet.Tables[0].Rows[0].ItemArray[0];

}

keep getting an error

Thanks,

Stelly
 
CS0266: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?)
 
SELECT MAX([book].[PriKey]) AS max_book FROM [book];

EDIT: See Below! I thought it might have been something wrong with the use of the MAX() function...I was wrong!
 
Last edited:
dataSet.Tables[0].Rows[0].ItemArray[0] returns an object.
You need to cast this to an int for it to work as your function returns an int type.

Code:
(int)dataSet.Tables[0].Rows[0].ItemArray[0];
 
Haircut said:
dataSet.Tables[0].Rows[0].ItemArray[0] returns an object.
You need to cast this to an int for it to work as your function returns an int type.

Code:
(int)dataSet.Tables[0].Rows[0].ItemArray[0];

Of course :) Thanks mate... thought I missed something

Stelly
 
Back
Top Bottom