Cannot Find Table 0 Asp Net Error
Contents |
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
Cannot Find Table 1 In C#
this site About Us Learn more about Stack Overflow the company Business how to solve 'cannot find table 0' Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Cannot Find Table 0 Dataset C#
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 cannot find table 1 dataset Error :Cannot Find Table 0 up vote 4 down vote favorite 1 I am seeing an error regarding cannot find table 0, where the dataset doesn't contain the table data. This is my code to fetch rows from a table: DataTable dt = new DataTable(); SqlConnection sqlconnection; sqlconnection = new SqlConnection(@"connectionstring"); sqlconnection.Open(); string sql = "Select (supplier_id,name) from supplier_info where supplier_id= '"+supplierid+"'"; SqlCommand system.indexoutofrangeexception: cannot find table 0. cmd = new SqlCommand(sql, sqlconnection); cmd.CommandType = CommandType.Text; SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataSet dtset = new DataSet(); adpt.Fill(dt); dt = dtset.Tables[0]; DataRow dr; dr = dt.Rows[0]; sqlconnection.Close(); return dr; Business logic code: Cust_datalogic dc = new Cust_datalogic(); //datalogic class DataTable dt = new DataTable(); DataRow dr; dr=dc.GetSupplierInfo(id); //method Supplier_BLL bc = new Supplier_BLL(); //business logic class bc.Ssup_ID = dr[0].ToString(); bc.Ssup_name = dr[1].ToString(); return bc; c# sql-server-2008 share|improve this question edited Feb 13 '14 at 6:56 Mark Bell 16.3k1374111 asked Feb 1 '14 at 8:04 Bhargav Amin 89118 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted Your problem area in your code is adpt.Fill(dt); //You are filling dataTable dt = dtset.Tables[0]; // You are assigning Table[0] which is null or empty Change it to adpt.Fill(dtset); //Fill Dataset dt = dtset.Tables[0]; //Then assign table to dt OR Your can directly use SqlDataAdapter to Fill DataTable thus no need of DataSet. Just remove DataSet, use SqlDataAdapter adpt = new SqlDataAdapter(cmd); adpt.Fill(dt); DataRow dr = dt.Rows[0]; share|improve this answer edited Feb 1 '14 at 8:14 answered Feb 1 '14 at 8:08 Satpal 76.
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions
Cannot Find Table 0 Stored Procedure
ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a cannot find table 0 sql server 2008 Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL
Sql Cannot Find Table 0
/ WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development http://stackoverflow.com/questions/21495678/error-cannot-find-table-0 Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help http://www.codeproject.com/Questions/446149/errore-cannot-find-table Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ errore: cannot find table 0. Rate this: Please Sign up or sign in to vote. See more: C# ASP.NET Hi, I have one table in sql bank, but when i run my program gives me an error message:cannot find table 0. for (int i = 0; i <= ds.Tables[0].Rows.Count; i++) { cmd.CommandText = @"select * from metb"; da.SelectCommand = cmd; da.Fill(ds); string fnList = ds.Tables[0].Rows[i]["fn"].ToString(); Label1.Text += fnList+"/n"; } Posted 23-Aug-12 22:01pm me64518 Add a Solution 3 solutions Top Rated Most Recent Rate this: Please Sign up or sign in to vote. Solution 2 Accept Solution Reject Solution It looks like your are trying to loop through the dataset before you fill it. You need to add or refresh the rows in dataset first and then loop through the rows. something like this cmd.CommandText = @"select * from metb"; da.SelectCommand = cmd; da.Fill(ds); if (ds.Tables.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string fnList = ds.Tables[0].Rows[i]["fn"].ToString(); Label1.Text += fnList+"/n"; } } Permalink Posted 23-Aug-12 22:19pm __TR__29K Updated 23-Aug-12 22:33pm pramodhegde8814.8K v3 Comments me64 24-Aug-12 4:24am it gives the mes
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All http://www.codeproject.com/Questions/569489/Hii-plusiplusamplususingplusfollowingplussimpleplu Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS cannot find Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics cannot find table help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ Database error - Cannot find table 0 Rate this: Please Sign up or sign in to vote. See more: C# ASP.NET .NET .NET4 Hi. I am using following simple statements in my cs file and getting error "cannot find table 0"... Unable to understand why..? I have one table in my database login(name,pwd)... protected void Button1_Click(object sender, EventArgs e) { if (!Page.IsPostBack) a = 0; con = new SqlConnection(); myHostName = Dns.GetHostName().ToString(); con.ConnectionString = ConfigurationManager.AppSettings["SqlConnectionString"]; sql = "select * from login"; adp = new SqlDataAdapter(sql, con); ds = new DataSet(); try { adp.Fill(ds); } catch (Exception ex) { } int i; // Label3.Text = "asdfasd" + ds.Tables.Count.ToString(); bool flag=false; if (a <= 2) { if (ds.Tables[0].Rows.Count > 0)//this line is shwoing error { for (i = 0; i < ds.Tables[0].Rows.Count; i++) { if ((txtLName.Text == ds.Tables[0].Rows[i]["name"].ToString()) && (txtPwd.Text == ds.Tables[0].Rows[i]["pwd"].ToString())) { flag = true; goto b; } else { flag = false; } } } } else { L