Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem in delete in access

Problem in delete in access

Scheduled Pinned Locked Moved ASP.NET
helpcsharpdebugging
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jacal99
    wrote on last edited by
    #1

    i am getting the error Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized. on this line OleDbCom.Fill(ds,"users"); my all code is as under. ------------------------------ <%@ Page Language="C#" Debug = "True"%> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.OleDb" %> // Insert page code here OleDbConnection OleDbCon; void page_Load(Object sender, EventArgs e) { OleDbConnection OleDbCon = new OleDbConnection ("Provider=Microsoft.Jet.OleDb.4.0; Data Source=d:\\access1.mdb"); BindGrid(); } void dg_delete(Object sender, DataGridCommandEventArgs e) { String deleteCmd = "DELETE from users where username = @uid"; OleDbCommand OleDbCom = new OleDbCommand(deleteCmd, OleDbCon); OleDbCom.Parameters.Add(new OleDbParameter("@Id", OleDbType.VarChar, 11)); OleDbCom.Parameters["@uid"].Value = dg.DataKeys[(int)e.Item.ItemIndex]; OleDbCom.Connection.Open(); try { OleDbCom.ExecuteNonQuery(); Message.Text = "Record Deleted"; } catch (OleDbException) { Message.Text = "ERROR Could not delete record"; Message.Style["color"] = "red"; } OleDbCom.Connection.Close(); BindGrid(); } public void BindGrid() { OleDbDataAdapter OleDbCom = new OleDbDataAdapter("select * from users", OleDbCon); DataSet ds = new DataSet(); OleDbCom.Fill(ds,"users"); dg.DataSource=ds.Tables["users"].DefaultView; dg.DataBind(); }

    Mazhar Hussain

    A 1 Reply Last reply
    0
    • J jacal99

      i am getting the error Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized. on this line OleDbCom.Fill(ds,"users"); my all code is as under. ------------------------------ <%@ Page Language="C#" Debug = "True"%> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.OleDb" %> // Insert page code here OleDbConnection OleDbCon; void page_Load(Object sender, EventArgs e) { OleDbConnection OleDbCon = new OleDbConnection ("Provider=Microsoft.Jet.OleDb.4.0; Data Source=d:\\access1.mdb"); BindGrid(); } void dg_delete(Object sender, DataGridCommandEventArgs e) { String deleteCmd = "DELETE from users where username = @uid"; OleDbCommand OleDbCom = new OleDbCommand(deleteCmd, OleDbCon); OleDbCom.Parameters.Add(new OleDbParameter("@Id", OleDbType.VarChar, 11)); OleDbCom.Parameters["@uid"].Value = dg.DataKeys[(int)e.Item.ItemIndex]; OleDbCom.Connection.Open(); try { OleDbCom.ExecuteNonQuery(); Message.Text = "Record Deleted"; } catch (OleDbException) { Message.Text = "ERROR Could not delete record"; Message.Style["color"] = "red"; } OleDbCom.Connection.Close(); BindGrid(); } public void BindGrid() { OleDbDataAdapter OleDbCom = new OleDbDataAdapter("select * from users", OleDbCon); DataSet ds = new DataSet(); OleDbCom.Fill(ds,"users"); dg.DataSource=ds.Tables["users"].DefaultView; dg.DataBind(); }

      Mazhar Hussain

      A Offline
      A Offline
      Aryadip
      wrote on last edited by
      #2

      Hi, you need to call the "Open()" method on the connection object OleDbConnection OleDbCon = new OleDbConnection ("Provider=Microsoft.Jet.OleDb.4.0; Data Source=d:\\access1.mdb"); OleDbCon.Open(); and then do the rest of the processing... hope that solves your problem.... regards, Aryadip. Cheers !! and have a Funky day !!

      J 1 Reply Last reply
      0
      • A Aryadip

        Hi, you need to call the "Open()" method on the connection object OleDbConnection OleDbCon = new OleDbConnection ("Provider=Microsoft.Jet.OleDb.4.0; Data Source=d:\\access1.mdb"); OleDbCon.Open(); and then do the rest of the processing... hope that solves your problem.... regards, Aryadip. Cheers !! and have a Funky day !!

        J Offline
        J Offline
        jacal99
        wrote on last edited by
        #3

        hi ok i will try this at home as you said.... and what about my other question that i have posted above ... check it also.. ok thx bye tc. Mazhar Hussain

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups