I have this public DataTable that I am trying to run an sql query in, but the dang thing wont work…
public DataTable get_OrderTransaction_Master_ByOrderID(Int64 orderID)
{
cn = new SqlConnection(objCommon.IpcConnectionString);
cmd = new SqlCommand("select * from dbo.OrderTransaction_Master where orderID = " + orderID, cn);
cmd.CommandType = CommandType.Text;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
I get a red line under get_OrderTransaction_Master_ByOrderID saying
Error 3 'OrderTransaction_Master.get_OrderTransaction_Master_ByOrderID(long)': not all code paths return a value C:\IPC\App_Code\OrderTransaction_Master.cs 32 22 http://localhost/ipc/
What Am I doing wrong?
The return type of your method is a
DataTable, but you don’t have a return statement in your method. You are also executingcmd.ExecuteNonQuery(), where you should be doingcmd.ExecuteReader()and loading aDataTableI put the
SqlConnection,SqlCommandandSqlDataReaderinusingstatements. This will properly dispose of the objects (close the connections, etc) once the using statement is exited.