petela
01-07-2005, 08:42 PM
Hi,
I am in the process of learning how to read and write to a database using .NET methods. I came across the relevant article contained in the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughusingdatagridwebcontroltoreadwritedata.asp
It is fairly straightforward, but there seems to be a problem with the CategoriesRow method, which is used to find a specific row in the dataset. After doing some research, I have found that others are having problems with this method. Here is my code (offending lines in red, error message at bottom):
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace bridgeport
{
public class editlogin : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter LoginSqlDataAdapter;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection LoginSqlConnection;
protected System.Web.UI.WebControls.DataGrid LoginDataGrid;
protected bridgeport.LoginDataSet loginDataSet;
private void Page_Load(object sender, System.EventArgs e)
{
LoginSqlDataAdapter.Fill(loginDataSet);
if (!IsPostBack)
{
LoginDataGrid.DataBind();
}
}
private void LoginDataGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
LoginDataGrid.EditItemIndex = e.Item.ItemIndex;
LoginDataGrid.DataBind();
}
private void LoginDataGrid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
LoginDataGrid.EditItemIndex = -1;
LoginDataGrid.DataBind();
}
private void LoginDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string loginName, loginPassword;
// Get the value of the key field of the row bing updated
string key = LoginDataGrid.DataKeys[e.Item.ItemIndex].ToString();
TextBox tb;
// Get the value of the TextBox control in the third column
tb = (TextBox)(e.Item.Cells[2].Controls[0]);
loginName = tb.Text;
loginDataSet.CategoriesRow r;
r = loginDataSet.Categories.FindByCategoryID(int.Parse(key)); }
}
}
c:\inetpub\wwwroot\visual studio projects\bridgeport\editlogin.aspx.cs(150,4): error CS0118: 'bridgeport.editlogin.loginDataSet' denotes a 'field' where a 'class' was expected
Any ideas on how to fix the problem?
Thanks,
petela
I am in the process of learning how to read and write to a database using .NET methods. I came across the relevant article contained in the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughusingdatagridwebcontroltoreadwritedata.asp
It is fairly straightforward, but there seems to be a problem with the CategoriesRow method, which is used to find a specific row in the dataset. After doing some research, I have found that others are having problems with this method. Here is my code (offending lines in red, error message at bottom):
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace bridgeport
{
public class editlogin : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter LoginSqlDataAdapter;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection LoginSqlConnection;
protected System.Web.UI.WebControls.DataGrid LoginDataGrid;
protected bridgeport.LoginDataSet loginDataSet;
private void Page_Load(object sender, System.EventArgs e)
{
LoginSqlDataAdapter.Fill(loginDataSet);
if (!IsPostBack)
{
LoginDataGrid.DataBind();
}
}
private void LoginDataGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
LoginDataGrid.EditItemIndex = e.Item.ItemIndex;
LoginDataGrid.DataBind();
}
private void LoginDataGrid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
LoginDataGrid.EditItemIndex = -1;
LoginDataGrid.DataBind();
}
private void LoginDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string loginName, loginPassword;
// Get the value of the key field of the row bing updated
string key = LoginDataGrid.DataKeys[e.Item.ItemIndex].ToString();
TextBox tb;
// Get the value of the TextBox control in the third column
tb = (TextBox)(e.Item.Cells[2].Controls[0]);
loginName = tb.Text;
loginDataSet.CategoriesRow r;
r = loginDataSet.Categories.FindByCategoryID(int.Parse(key)); }
}
}
c:\inetpub\wwwroot\visual studio projects\bridgeport\editlogin.aspx.cs(150,4): error CS0118: 'bridgeport.editlogin.loginDataSet' denotes a 'field' where a 'class' was expected
Any ideas on how to fix the problem?
Thanks,
petela