hi team,
please help to correct the following code below which i have written but its giving an error of 'ds' and 'ddl' doesnt contain in the context
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Odbc;
public partial class creatmenu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillddlMainMenu();
}
}
public void FillddlMainMenu()
{
OdbcConnection conn = new OdbcConnection("dsn=parcel;uid=dba;pwd=sql");
DataSet dsFill = new DataSet();
OdbcDataAdapter OdbcDa = new OdbcDataAdapter("Select MainMenuId,MainMenu from MainMenu", conn);
conn.Open();
OdbcDataAdapter.Fill(ds);
ddlMainMenu.DataSource = DS;
ddlMainMenu.DataBind();
}
protected void btnMainmenu_Click(object sender, EventArgs e)
{
OdbcCommand cmd;
int active;
if (chkMActive.Checked)
{
active = 1;
}
else
{
active = 0;
}
OdbcConnection conn = new OdbcConnection("dsn=parcel;uid=dba;pwd=sql");
cmd = new OdbcCommand("INSERT INTO mainmenu(mainmenu, mcontent, menuorder,isactive)VALUES('" + txtMainmenu.Text + "','" + txtMContent.Text + "'," + Convert.ToInt16(MOrder.SelectedItem.Value) + "," + active + ")", conn);
conn.Open();
//cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
conn.Close();
FillddlMainMenu();
Response.Redirect("creatmenu.aspx");
}
protected void btnSubmenu_Click(object sender, EventArgs e)
{
int active;
if (chkSActive.Checked)
{
active = 1;
}
else
{
active = 0;
}
OdbcCommand cmd;
OdbcConnection conn = new OdbcConnection("dsn=parcel;uid=dba;pwd=sql");
cmd = new OdbcCommand("INSERT INTO submenu(submenu, content, menuorder,parentid,isactive)VALUES('" + txtSubmenu.Text + "','" + txtSContent.Text + "'," + Convert.ToInt16(ddlSOrder.SelectedItem.Value) + "," + Convert.ToInt16(ddlMainMenu.SelectedItem.Value) + "," + active + ")", conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect("creatmenu.aspx");
}
}
regard
george
Loading

SenthilkumarRank #387 · 6.5K reputationPosted Mar 27, 2012, 10:49 PM EDT
There is no dataset called "ds" in your code eventhough you are trying to fill.
It has to be replaced with the "dsFill" dataset instead of "ds".
I am not finding anything name called "ddl" in your code.
Please check it and let me know. If it solves your problem then mark it as "Accepted Answer"
Krishna GaradRank #191 · 12.8K reputationPosted Mar 27, 2012, 11:13 PM EDT
public void FillddlMainMenu()
{
OdbcConnection conn = new OdbcConnection("dsn=parcel;uid=dba;pwd=sql");
DataSet dsFill = new DataSet();
OdbcDataAdapter OdbcDa = new OdbcDataAdapter("Select MainMenuId,MainMenu from MainMenu", conn);
conn.Open();
OdbcDataAdapter.Fill(ds);
ddlMainMenu.DataSource = DS;
ddlMainMenu.DataBind();
}
in above menu you needs to change this two lines
OdbcDataAdapter.Fill(dsFill);
ddlMainMenu.DataSource = dsFill;
george wambui17 reputationPosted Mar 27, 2012, 11:16 PM EDT
Krishna GaradRank #191 · 12.8K reputationPosted Mar 27, 2012, 11:27 PM EDT
SenthilkumarRank #387 · 6.5K reputationPosted Mar 27, 2012, 11:55 PM EDT
You mentioned like
OdbcDataAdapter.Fill(dsFill);
ddlMainMenu.DataSource = dsFill;
He is not filling the dataset with instance of OdbcDataAdapter class.
It should be like
OdbcDa.Fill(dsFill);
ddlMainMenu.DataSource = dsFill;
I think the control may be there in the design page (.aspx). Sometimes the instance of the control may not be updated in the desiger code file.