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
SenthilkumarPosted Mar 28, 2012, 3:55 AM
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.
Krishna GaradPosted Mar 28, 2012, 3:27 AM
george wambuiPosted Mar 28, 2012, 3:16 AM
Krishna GaradPosted Mar 28, 2012, 3:13 AM
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;
SenthilkumarPosted Mar 28, 2012, 2:49 AM
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"