Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I' am getting the problem in debug in C# web site is cannot find table 0 on this code



C#
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using ORCMS.DAL;
using ORCMS.Entity;
public partial class Admin_ResourceRegister : System.Web.UI.Page
{
    string war, amc;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {          
            ControlBinder.BindDepartments(dpdldept);
            ControlBinder.BindEmployee(dpdlUserName);
            ControlBinder.BindResourceCategory(dpdlCategory);              
        }
    }
    protected void dpdlCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        ControlBinder.BindResourceType(dpdlType, dpdlCategory);
    }    
    protected void btnclear_Click(object sender, EventArgs e)
    {   
        txtResourceName.Text = string.Empty;
       
        dpdlCategory.SelectedItem.Value = string.Empty;
        dpdlType.SelectedItem.Value = string.Empty;
        dpdlUserName.SelectedItem.Value = string.Empty;
        txtconfig.Text = string.Empty;
        txtipadd.Text = string.Empty;
        txtUsedFor.Text = string.Empty;
        dpdldept.SelectedItem.Value = string.Empty;
        txtregdate.Text = string.Empty;
        
       
    }   
    
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        ResourceRegistration oResReg = new ResourceRegistration();
        DALResorceRegistration oDALResReg = new DALResorceRegistration();
                 
        string sError=string.Empty;
        if (rdbWarNo.Checked == true)
        {
            war = rdbWarNo.Text;
        }
        else
        {
            war = rdbWarYes.Text;
        }
        if (rdbAMCNo.Checked == true)
        {
            amc = rdbAMCNo.Text;
        }
        else
        {
            amc = rdbAMCYes.Text;
        }
                    
        try
        {
            oResReg.Config = txtconfig.Text;
            oResReg.DeptID = Convert.ToInt32(dpdldept.SelectedItem.Value);
            oResReg.IpAdd = txtipadd.Text;
            oResReg.RegDate = Convert.ToDateTime(txtregdate.Text);
            oResReg.ResType = dpdlType.SelectedItem.Value;
            oResReg.RseName = txtResourceName.Text;
            oResReg.UsedFor = txtUsedFor.Text;
            oResReg.UserID = Convert.ToInt32(dpdlUserName.SelectedItem.Value);
            oResReg.AMC = amc;
            oResReg.warranty = war;
            DataSet oDsResult = oDALResReg.InsertResourceDetails(oResReg, ref sError);
            if (oDsResult != null && oDsResult.Tables != null &&
                oDsResult.Tables[0].Rows.Count > 0 &&
                oDsResult.Tables[0].Rows[0]["RC"].ToString().Equals("0"))
            {                
                txtconfig.Text = string.Empty;
                txtipadd.Text = string.Empty;
                txtregdate.Text = string.Empty;
                txtResourceName.Text = string.Empty;
                txtUsedFor.Text = string.Empty;
                dpdlCategory.SelectedIndex = dpdldept.Items.IndexOf(
                dpdldept.Items.FindByValue("Select"));
                dpdldept.SelectedIndex = dpdldept.Items.IndexOf(
                dpdldept.Items.FindByValue("Select"));
                dpdlType.SelectedIndex = dpdldept.Items.IndexOf(
                dpdldept.Items.FindByValue("Select"));
                dpdlUserName.SelectedIndex = dpdldept.Items.IndexOf(
                dpdldept.Items.FindByValue("Select Employee Name"));
                lblServerMsg.Text = oDsResult.Tables[0].Rows[0]["ServerMsg"].ToString();
            }
            else
            {
                lblServerMsg.Text = oDsResult.Tables[0].Rows[0]["ServerMsg"].ToString();
            }
        }
        catch (Exception oEx)
        {
            lblServerMsg.Text = oEx.Message;
        }        
    }
Posted
Updated 8-May-11 18:46pm
v2
Comments
arindamrudra 9-May-11 1:17am    
What is the error that you are getting? If you are getting "cannot find table 0" then please check the answer from Sandeep Mewara. Or if you want to bypass this problem then use, if((oDsResult != null) && (oDsResult.Tables.Count > 0) && (oDsResult.Tables[0] != null) && (oDsResult.Tables[0].Rows.Count > 0))

1 solution

C# web site is cannot find table 0 on this code
It simply means that the database does not returned any data when you ran your query.

You need to debug and see in the Database layer if the data was returned. Check for the query formed if correct and working. Run the raw query formed directly on database and see if any data is being returned. If so, see how you are handling it and if you are using correct ADO.NET code to pass on the data.
 
Share this answer
 
Comments
arindamrudra 9-May-11 1:21am    
Sandeep, I don't know why someone voted 1 for this answer. But, I also agree with you. My +5 to your answer.
Sandeep Mewara 9-May-11 1:30am    
Difficult for me to say why was downvoted! :)
Thanks for the vote! :thumbsup:
Pong D. Panda 9-May-11 2:14am    
Counter voted
Sandeep Mewara 9-May-11 2:34am    
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900