Advertisement

05.10.2008 at 09:03PM PDT, ID: 23392356
[x]
Attachment Details

error - Cannot find table 0

Asked by reks_p6 in Programming for ASP.NET

Hi I'm getting the following error when i try to select the checkbox in a gridview and press the submit button in order to update the checked value in the database.

error- cannot find table 0
throwing exception in Data Access Layer

I'm  a beginner so could anyone help me out with this issue as to why am getting this

thanks
reks
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
//Data Access code
 
public DataTable getTable(string strQry)
    {
        SqlDataAdapter sqlAdp = new SqlDataAdapter(strQry, strSqlConn);
        try
        {
            strSqlConn.Open();
            DataSet ds = new DataSet();
            sqlAdp.Fill(ds, "Temp");
            return ds.Tables[0];//This is where am getting error
        }
        catch (SqlException ex)
        {
            throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            sqlAdp.Dispose();
            sqlAdp = null;
            strSqlConn.Close();
        
        }
 
 
    }
 
//PracticeGridview.cs code
 
public partial class PracticeGridview : System.Web.UI.Page
{
    DataAccess da = new DataAccess();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGrid();
        }
 
    }
 
    private void BindGrid()
    {
 
        StringBuilder sb = new StringBuilder();
        sb.Append("Select AppID,Application from Approval");
        DataTable dt = new DataTable();
        dt = da.getTable(sb.ToString());
        GridView1.DataSource = dt;
        GridView1.DataBind();
 
    }
 
    protected void Button1_Click1(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            int AppID = (int)GridView1.DataKeys[i][0];
            CheckBox cb = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
 
            if (cb.Checked)
            {
 
                StringBuilder sb = new StringBuilder();
                // sb.Append(GridView1.Rows[i].Cells[1].ToString());
 
                sb.Append("UPDATE Approval SET Approved='true' WHERE AppID=@AppID  ");
                sb.Replace("@AppID", AppID.ToString());
                da.getTable(sb.ToString());
                BindGrid();
            }
        }
    }
}
[+][-]05.10.2008 at 09:29PM PDT, ID: 21541470

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Programming for ASP.NET
Sign Up Now!
Solution Provided By: JimBrandley
Participating Experts: 2
Solution Grade: B
 
 
[+][-]05.12.2008 at 12:24AM PDT, ID: 21545112

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628