Error System.invalidoperationexception No Data Exists For The Row/column
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings no data exists for the row column vb net and policies of this site About Us Learn more about Stack Overflow
No Data Exists For The Row/column. Oledbdatareader
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags no data exists for the row or column. oracledatareader Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up No data exists for the row/column up vote 1 down vote favorite 1 While executing the following code in ASP.NET with C#, I am getting an exception like "No data exists for the row/column." OdbcConnection DbConnection = new OdbcConnection(ConfigurationManager.AppSettings["ConnectionStr"]); DbConnection.Close(); string cmdText = "SELECT Team_ID FROM team_details WHERE Team_Code=?"; OdbcCommand cmd = new OdbcCommand(cmdText, DbConnection); cmd.Parameters.Add("?Code", OdbcType.VarChar).Value = tbCode.Text; DbConnection.Open(); OdbcDataReader DR = cmd.ExecuteReader(); DR.Read(); if (DR.GetValue(0) != DBNull.Value) { args.IsValid = false; } else { args.IsValid = true; } DbConnection.Close(); I'm using Visual Studio 2008 and MySQL. I'm using MySql ODBC connector 5.1 and MDAC2.8. Please guide me how to resolve this. c# asp.net odbc mdac share|improve this question edited Jun 25 '11 at 8:29 Jon 10k63753 asked Jun 25 '11 at 8:26 Able Alias 2,12343461 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote accepted The Read method returns a boolean indicating whether any rows were returned or not, so you should always test this value prior to accessing the result of the reader. OdbcDataReader DR = cmd.ExecuteReader(); if (DR.Read() && DR.GetValue(0) != DBNull.Value) { args.IsValid = false; } else { args.IsValid = true; } DbConnection.Close(); EDIT ---- You should also consider using the connections since this will ensure that is is closed (disposed) even though an exception occurs inside the using statement. You could also get rid of the if statement, but that is a matter o
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up DataReader error - “no data exist for the row/column” - when data exists? up vote 1 down http://stackoverflow.com/questions/6476711/no-data-exists-for-the-row-column vote favorite I need some help in understanding my error. I want to read data from table, however I get error such as "no data exist for the row/column". I dont understand it, since I actually have rows and columns in there. WinForms. Thanks! //this is how i insert data into table, works fine public void b1_Click(object sender, EventArgs e) { SqlCeCommand command = new SqlCeCommand("INSERT INTO tbl1(Name, LastName) VALUES (@Name, @LastName)", http://stackoverflow.com/questions/12773396/datareader-error-no-data-exist-for-the-row-column-when-data-exists conn); command.Parameters.AddWithValue("@Name", l1.Text); command.ExecuteNonQuery(); } //this is how i try to read data from the same table public void b2_Click(object sender, EventArgs e) { SqlCeConnection conn = new SqlCeConnection(@"Data Source=C:test.sdf"); conn.Open(); SqlCeCommand command = new SqlCeCommand("SELECT * FROM tbl1", conn); SqlCeDataReader reader = command.ExecuteReader(); //error here string Name = reader.GetString(0); label.Text = Name; } c# sql-server-ce share|improve this question edited Oct 7 '12 at 23:18 user166390 asked Oct 7 '12 at 22:23 Leo Storm 2216 Please make sure to include only the relevant code next time (go ahead and remove the irrelevant code now); the method definition can also be removed as it doesn't apply to the problem. –user166390 Oct 7 '12 at 23:21 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted Problem is with your results' loading. SqlCeDataReader reader = command.ExecuteReader(); while (reader.Read()) { string Name = reader.GetString(0); } So you use the Read method to iterate through the results. Or, if you just have one result then you can also use the ExecuteScalar string Name = reader.ExecuteScalar().ToString(); share|improve this answer answered Oct 7 '12 at 22:28 Randolf Rincón Fadul 11k63062 greatly appreciated! –Leo Storm Oct 7 '12 at 22:34 The key point is that Read() must be invoked o
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Retired Forums/Portal Starter Kit (RETIRED)/Error: No data exists for the row/column. Error: No data exists for the row/column. RSS 3 replies Last post Oct 03, 2003 04:58 PM by sstoos https://forums.asp.net/t/83359.aspx?Error+No+data+exists+for+the+row+column+ ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply byoung None 0 Points 15 Posts Error: No data exists for the row/column. Nov 08, 2002 04:59 PM|byoung|LINK I'm converting the free Survey Module from the SQL one into an Access Database version. It's been quite educational, which is mostly what I'm doing it for right now. Anyway, I've no data worked through many error messages, and have come to one I just can't crack myself. I've tried doing some searching on the web but I can't find a solution to my headache. The problem is when I add the Survey Module to a page it doesn't have any default question or anything in the database. Problem is, when the page loads it tries to find out if there are any questions, no data exists and when it runs this particular module it errors out complaining the following error message: Exception Details: System.InvalidOperationException: No data exists for the row/column. Here is what is calling the function, from the .ascx page: ---- Dim RowCount As Integer = 0 RowCount = SurveyCheck.ExistSurvey(ModuleId) If RowCount > 0 Then... ----- Here is the entire function. I do now that if I manually add a Survey Question into the database then this does not occur. So I'm guessing that since there is nothing setup in the database that it is freaking over a null value or some type of thing. I've gone over the SQL method and the Access method a few times and can't seem to find out if I can set a trap to set a default if no records are returned. Help! --- Public Function ExistSurvey(ByVal ModuleID As Integer) As Integer Dim myTools As New Tools() Dim myRTConnection As String = myTools.GetConnectionString() '<-- Create Instance of Connection and Command Object --> Dim myConnection As New OleDbConnection(myRTConnection) Dim mySQL As String = "SELECT SurveyID FROM Surveys WHERE (ModuleID = " & ModuleID & ")" myConnection.Open() Dim myCommand As New OleDbCommand(mySQL, myConnection) Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) myReader.Read() Dim MyRowCount As Integer = 0 MyRowCount = myReader.GetInt32(0) myReader.Close() myConnection.