C# - Using Oracle Query And Using Executescalar() To Fetch Data?
Jan 4, 2010
I am using following oracle query and using executescalar() to fetch data
sql = "select username from usermst where userid=2"
string getusername = command.executescalar();
But It is showing me error "System.NullReferenceException: Object reference not set to an instance of an object"
This error comes when there is no row exist in database for userid=2
I am a biggner in SQL DB . but i started a complicated and painfull work in SQL SERVER 2008. the problem convert Oracle hierarchical query to SQL query. the query
SELECT DISTINCT LEVEL LVL, SCH.NSCHEDULE_SL, SCH.NSCHEDULE_SL_FM, SCH.CSHED_CNAME FROM FA_SCHEDULES SCH WHERE LEVEL = 1 AND NSCHEDULE_SL_FM IS NULL AND NBRANCH_SL = 2 CONNECT BY PRIOR SCH.NSCHEDULE_SL_FM = SCH.NSCHEDULE_SL AND NBRANCH_SL = 2
I'm unable to fetch just one integer value using this LINQ-query. LINQ seems to return everything as IEnumerable but I don't want that. First query should return just one string value which is then used in another query. That one should return integer which is also return value for method:
public static long GetTableIdByTableName(string name) { var result = (from aTable in objScope.Extent<Table>() where aTable.Name == name select { aTable.Id }); return ??????????? }
How can I make this get a specific users data, Example user enters his 3 digit code in the badge text box so that only his information is shown. Can I add a where clause to the select command? or is there a better way to do this? Also is there a good book out there with information about asp.net, c# and oracle.
// string Badge = "100000" + Request.Form["xBadgeTextBox"]; in default.aspx.cs //"SELECT * FROM CLOCK_HISTORY WHERE BADGE ='" + Badge + "'"; would
I have a number of automatically generated data access classes to handle things like inserts & updates. These look like:
cmd.CommandType = CommandType.Text cmd.CommandText = "UPDATE myTable set f1 = :f1, f2 = :f2, f3 = :f3 where id = :id" cmd.Parameters.AddWithValue(":f1", _f1) cmd.Parameters.AddWithValue(":f2", _f2) cmd.Parameters.AddWithValue(":f3", _f3) cmd.ExecuteNonQuery()
If I were to re-write the sql to do what I want, it would look something like
cmd.CommandText = "UPDATE myTable set f1 = pkg.getMyValue, f2 = :f2, f3 = :f3 where id = :id"
Is there any way to do this by setting _f1 to a "special" value, without changing the update SQL or the way the parameters are set? Only in certain cases will I need to set the value of f1 - most of the time, it will be null.
Using .net 2.0, and system.data.oracleclient against oracle 11.
To write a join query with or condition. It means a query has two inner join, here it is possible to fetch the records, if one inner join is true and other is false. I got a record when only two join conditions are true.
We have a site that is runnig II7 64 bit with the oracle .net 64 bit provider, when I try and open this in web developer 2010 express (I'm running windows 7 pro 64bit) it says it can't load the oracle dll as its an incorrect format. I got the impress that web developer 2010 was 64bit capable.
Ofcourse this is extremly annoying as I don't get any syntax formatting for the project or intellisense.
I have VS 2010 professional. I am trying to open "ASP.Net Configuration" through Project -> ASP.Net Configuration.
It pops up the Notification about the ASP.Net Development Server localhost but doesn't open ASP.Net Configuration in the default browser.I clicked on the Root Url (by double clicking on the 'development server' at the right bottom from Notification Manager).
It throws following error
"An error was encountered. Please return to the previous page and try again."
Clicking on "How do i use this tool".It opened page with error.
I have this SQL Select statement to select the basket id where the user id equals a specific ID.I want to store the result of the query in a variable, so I thought I could have done:
BasketPage.SelectCommand="SELECT BasketID FROM tblBasket WHERE (UserID = '9f96bd94-91b9-4328-8214-4eac179c3a26')" var BasketID = BasketPage.ExecuteScalar().ToString();
But apparently I need to create a new instance of an SQL Command for it to work, how can I do this for the BasketPage Select Command?
I have the SqlCommand Problem. cmd is the sqlcommand and when run cmd.Executescalar(), what will it return?? As I have the problem below code that it always prompt invalid cast which may be in the assigning BAtchno. What do you think?? How to Correct below code?? --------------------------------------------------------
sSQL = "select max(batchno) from QI_WMS.dbo.WMS_StockRelease_Shipment with(nolock) " + " where convert(varchar, SRDate, 111) = @DateReceive and WarehouseID=@WarehouseID";
I know for a fact that the SQL statement below returns NULL but my code statement "if (obj != null)" is not working.When I debug it I see a value of {} ... not sure what that is. Here is my code:
[Code]....
So, even if SQL returns NULL, it still validates obj as NOT NULL !
I posted a question about how to save the result of an SQL command to a variable and was told that the execute scalar method should be used, however I can't use it, I'm using the System.Data.SQLClient reference but still not finding it
I'm using Visual Studio 2008, and my database is SQL Server 2000.
I want to add a connection to the Server Explorer in VS. The Data source is Microsoft SQL Server (SqlClient). After entering in all my information and I click Test Connection, it is successful.
But when I click OK, I get the error:
Unable to add data connection. ExecuteScalar requires an open and available connection. The connection's current state is closed.
I have a simple procedure which updates a table. The procedure works fine and I have tested it in Management Studio. However when I am calling that procedure from code, nothing is happening. cmd.ExecuteScalar returns null when it should return the ID.Has anyone faced anything similar? Any pointers as to how this can be resolved?
Since both retruns the value. Then whats is the difference between ParameterDirection.ReturnValue and ExecuteScalar()
int i = Convert.ToInt32(cmd.ExecuteScalar()) objCmd.Parameters.Add("@ColumnnTest", SqlDbType.Decimal).Value = objPropertiesClassName.Columnnumeric; objCmd.Parameters["@Columnnumeric"].Direction = ParameterDirection.ReturnValue; objCmd.ExecuteNonQuery(); int i = (int)objCmd.Parameters["@Columnnumeric"].Value;
I hope this is the right forum for this question.The statement , object obj = cmd.ExecuteScalar() is returning 2010-10-22 18:25:36However is not bringing the last 3 digits (miliseconds).This is actually calling the following SQL query: select max(timeStamp) from Table1 which returns 2010-10-22 18:25:36.713 on query analyzer. As you can see "713" is not being included ...How do I bring this value?