Newbie Data grid question.

D

DC

Trying to use the classic CommandBuilder and datagrid binding method
under c# to update add and remove records form a single table database,
I keep getting the error.

"CS0117: 'System.Web.UI.WebControls.DataGrid' does not contain a
definition for 'SetDataBinding'"

Why would this be?


<%@ import namespace="System" %>
<%@ import namespace="System.Web" %>
<%@ import namespace="System.Web.UI" %>
<%@ import namespace="System.Web.UI.HtmlControls" %>
<%@ import namespace="System.Web.UI.WebControls" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.OleDb" %>

<html>
<head>

<title>Meetings Admin Page</title>


<META HTTP-EQUIV=REFRESH CONTENT=1800>

<link REL="ICON" HREF="http://www.met.rdg.ac.uk/favicon.ico">
<link REL="SHORTCUT ICON" HREF="http://www.met.rdg.ac.uk/favicon.ico">

<meta name="MSSmartTagsPreventParsing" content="TRUE">

<script language="C#" runat="server">

private void GridBind()
{

string ConnString ="Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=C:\\Program Files\\Common Files\\ODBC\\Data
Sources\\seminars.mdb;";

OleDbConnection myConnection= new OleDbConnection(ConnString);
DataSet SeminarsDataSet = new DataSet();

///fill the dataset
SeminarsAdapter.Fill(SeminarsDataSet, "SeminarsList");

///set the dataset as a datasource for windows datagrid

datagrid1.SetDataBinding(SeminarsDataSet, "SeminarsList");

}

private void btnSave_Click(object sender, System.EventArgs e)
{
try
{
///the following statement
///inserts
///updates
///deletes for you
/// Without the CommandBuilder, this line would fail.
SeminarsAdapter.Update(SeminarsDataSet,"SeminarsList");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

</script>

</head>



<body bgcolor=#FFFFFF>

<!-- Start of page header section -->

<!-- Stylesheet Location -->

<link rel="stylesheet" type="text/css"
href="/scripts/includes/metstyle.css">

<!-- Page Header info goes here -->

<center>

<H3>Seminars Admin Page</H3>

<asp:datagrid id="datagrid1" runat="server" />


</center>

</body>

</html>

--
_______________________________________________

DC

"You can not reason a man out of a position he did not reach through reason"

"Don't use a big word where a diminutive one will suffice."

"A man with a watch knows what time it is. A man with two watches is
never sure." Segal's Law
 
F

Frans Bouma [C# MVP]

DC said:
Trying to use the classic CommandBuilder and datagrid binding method
under c# to update add and remove records form a single table
database, I keep getting the error.

"CS0117: 'System.Web.UI.WebControls.DataGrid' does not contain a
definition for 'SetDataBinding'"

Why would this be?


Well, perhaps because the web's datagrid doesn't have a method called
SetDataBinding ? :)

Use .DataSource
and
.DataBind();

FB


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
D

DC

Doh!!!

Ok so a s a contiuation of this question why am i now getting the error
"CS0246: The type or namespace name 'SeminarsAdapter' could not be found
(are you missing a using directive or an assembly reference?)" for the
following code?

Is the SeminarsAdapter object out of scope for the "btnSave_Click" routine?

Thanks in advance,

<script language="C#" runat="server">

private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack != true)
{
BindData();
}
}

void BindData()
{
///connection string which will be different in your computer
string ConnString ="Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=C:\\Program Files\\Common Files\\ODBC\\Data
Sources\\seminars.mdb;";

OleDbConnection myConnection= new OleDbConnection(ConnString);

///instantiate OleDbDataAdapter to create DataSet
OleDbDataAdapter SeminarsAdapter = new OleDbDataAdapter("select *
from SeminarsList",myConnection);

/// the following is for creating automatic command builder
OleDbCommandBuilder SeminarsCmdBuilder = new
OleDbCommandBuilder(SeminarsAdapter);

DataSet SeminarsDataSet = new DataSet();

///fill the dataset
SeminarsAdapter.Fill(SeminarsDataSet, "SeminarsList");

///set the dataset as a datasource for windows datagrid

datagrid1.DataSource = SeminarsAdapter;
datagrid1.DataBind();

}

private void btnSave_Click(object sender, System.EventArgs e)
{
try
{
///the following statement
///inserts
///updates
///deletes for you
/// Without the CommandBuilder, this line would fail.

SeminarsAdapter.UpdateCommand = SeminarsCmdBuilder.GetUpdateCommand();
SeminarsAdapter.Update(SeminarsDataSet);
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}

Well, perhaps because the web's datagrid doesn't have a method called
SetDataBinding ? :)

Use .DataSource
and
.DataBind();

FB


--
_______________________________________________

DC

"You can not reason a man out of a position he did not reach through reason"

"Don't use a big word where a diminutive one will suffice."

"A man with a watch knows what time it is. A man with two watches is
never sure." Segal's Law
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top