473,394 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Error: Object doesn't support this property or method

I'm trying to create the form which would allow data entry
to the Client table, as well as modification and deletion
of existing data rows. For some reason the DataGrid part
of functionality stops working when I include data entry
fields to the form: I click on Delete or Edit inside of
DataGrid and get this error: "Error: Object doesn't
support this property or method"

If I remove data entry fields from the form - DataGrid
allows to delete or update data inside of itself. I don't
see how the data entry fields can cause DataGrid stop
working. I'm going to include my code here.

If you have an example of what I'm trying to do here,
please let me know where I can find it. (I'm just trying
to create a form to view, insert, update, and delete data
from the table.)

Thank you.

<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ page debug="true" trace="true" %>
<HTML>
<script language="C#" runat="server">

SqlConnection myConnection;

protected void Page_Load(Object Src, EventArgs E)
{
myConnection = new SqlConnection("user
id=sa;password=barrom;initial catalog=propmgmt;data
source=COMP1;Connect Timeout=30");

if (!IsPostBack)
BindGrid();
}

public void MyDataGrid_Edit(Object sender,
DataGridCommandEventArgs E)
{
MyDataGrid.EditItemIndex = (int)E.Item.ItemIndex;
BindGrid();
}

public void MyDataGrid_Cancel(Object sender,
DataGridCommandEventArgs E)
{
MyDataGrid.EditItemIndex = -1;
BindGrid();
}

public void MyDataGrid_Delete(Object sender,
DataGridCommandEventArgs e)
{
String deleteCmd = "DELETE from client where
client_id = @Client_Id";

SqlCommand myCommand = new SqlCommand(deleteCmd,
myConnection);
myCommand.Parameters.Add(new SqlParameter
("@Client_Id", SqlDbType.NVarChar, 10));
myCommand.Parameters["@Client_Id"].Value =
MyDataGrid.DataKeys[(int)e.Item.ItemIndex];

myCommand.Connection.Open();

try
{
myCommand.ExecuteNonQuery();
Message.InnerHtml = "<b>Record
Deleted</b><br>" + deleteCmd;
}
catch (SqlException)
{
Message.InnerHtml = "ERROR: Could not delete
record";
Message.Style["color"] = "red";
}

myCommand.Connection.Close();

BindGrid();
}

public void MyDataGrid_Update(Object sender,
DataGridCommandEventArgs E)
{
String updateCmd = "UPDATE client SET client_id =
@Client_Id, adr_id = @Adr_Id, locale_id = @Locale_id,
status = @Status, "
+ "start_date = @Start_date, expir_date =
@Expir_date, currency = @Currency where client_id =
@Client_Id";

SqlCommand myCommand = new SqlCommand(updateCmd,
myConnection);

myCommand.Parameters.Add(new SqlParameter
("@Client_Id", SqlDbType.NVarChar, 10));
myCommand.Parameters.Add(new SqlParameter
("@Adr_Id", SqlDbType.NVarChar, 20));
myCommand.Parameters.Add(new SqlParameter
("@Locale_id", SqlDbType.NVarChar, 20));
myCommand.Parameters.Add(new SqlParameter
("@Status", SqlDbType.NChar, 1));
myCommand.Parameters.Add(new SqlParameter
("@Start_date", SqlDbType.NVarChar, 19));
myCommand.Parameters.Add(new SqlParameter
("@Expir_date", SqlDbType.NVarChar, 19));
myCommand.Parameters.Add(new SqlParameter
("@Currency", SqlDbType.NVarChar, 10));

myCommand.Parameters["@Client_Id"].Value =
MyDataGrid.DataKeys[E.Item.ItemIndex];

String[] cols =
{"@Client_Id","@Adr_Id","@Locale_id","@Status","@S tart_date
","@Expir_date","@Currency"};

int numCols = E.Item.Cells.Count;
for (int i=2; i<numCols-1; i++) //skip first,
second and last column
{
String colvalue =((TextBox)E.Item.Cells
[i+1].Controls[0]).Text;

// check for null values in required fields
//if (i<7 && colvalue == "")
//{
// Message.InnerHtml = "ERROR: Null values
not allowed for Client ID, Name or Status";
// Message.Style["color"] = "red";
// return;
//}
myCommand.Parameters[cols[i-1]].Value =
Server.HtmlEncode(colvalue);
}

myCommand.Connection.Open();

try
{
myCommand.ExecuteNonQuery();
Message.InnerHtml = "<b>Record
Updated</b><br>" + updateCmd;
MyDataGrid.EditItemIndex = -1;
}
catch (SqlException e)
{
if (e.Number == 2627)
Message.InnerHtml = "ERROR: A record
already exists with the same primary key";
else
Message.InnerHtml = "ERROR: Could not
update record, please ensure the fields are correctly
filled out";
Message.Style["color"] = "red";
}

myCommand.Connection.Close();

BindGrid();
}

private void MyDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
for (int i = 0; i < e.Item.Controls.Count; i++)
{
try
{
if (e.Item.Controls[i].Controls
[0].GetType().ToString()
== "System.Web.UI.WebControls.TextBox")
{
TextBox tb = (TextBox)
e.Item.Controls[i].Controls[0];
tb.Text = Server.HtmlDecode
(tb.Text);
}
}
catch
{

}
}
}
}

public void AddClient_Click(Object sender, EventArgs
E)
{
if (client_id.Value == "" || adr_id.Value == "" ||
locale_id.Value == "")
{
Message.InnerHtml = "ERROR: Null values not
allowed for Client ID, Address ID, or Locale ID";
Message.Style["color"] = "red";
BindGrid();
return;
}

String insertCmd = "insert into client " +
" (client_id, adr_id, locale_id, status,
start_date, expir_date, currency) values " +
"(@client_id,@adr_id,@locale_id,@status,@start_dat e
,@expir_date,@currency)";

SqlCommand myCommand = new SqlCommand(insertCmd,
myConnection);

myCommand.Parameters.Add(new SqlParameter
("@client_id", SqlDbType.NVarChar, 20));
myCommand.Parameters["@client_id"].Value =
Server.HtmlEncode(client_id.Value);

myCommand.Parameters.Add(new SqlParameter
("@adr_id", SqlDbType.NVarChar, 20));
myCommand.Parameters["@adr_id"].Value =
Server.HtmlEncode(adr_id.Value);

myCommand.Parameters.Add(new SqlParameter
("@locale_id", SqlDbType.NVarChar, 20));
myCommand.Parameters["@locale_id"].Value =
Server.HtmlEncode(locale_id.Value);

myCommand.Parameters.Add(new SqlParameter
("@status", SqlDbType.NChar, 1));
myCommand.Parameters["@status"].Value =
Server.HtmlEncode(status.Value);

myCommand.Parameters.Add(new SqlParameter
("@start_date", SqlDbType.NVarChar, 19));
myCommand.Parameters["@start_date"].Value =
Server.HtmlEncode(start_date.Value);

myCommand.Parameters.Add(new SqlParameter
("@expir_date", SqlDbType.NVarChar, 19));
myCommand.Parameters["@expir_date"].Value =
Server.HtmlEncode(expir_date.Value);

myCommand.Parameters.Add(new SqlParameter
("@currency", SqlDbType.NVarChar, 10));
myCommand.Parameters["@currency"].Value =
Server.HtmlEncode(currency.Value);

myCommand.Connection.Open();

try
{
myCommand.ExecuteNonQuery();
Message.InnerHtml = "<b>Record Added</b><br>"
+ insertCmd.ToString();
}
catch (SqlException e)
{
if (e.Number == 2627)
Message.InnerHtml = "ERROR: A record
already exists with the same primary key";
else
Message.InnerHtml = "ERROR: Could not add
record, please ensure the fields are correctly filled out";
Message.Style["color"] = "red";
}

myCommand.Connection.Close();

BindGrid();
}

public void BindGrid()
{
SqlDataAdapter myCommand = new SqlDataAdapter
("select * from client", myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "client");

MyDataGrid.DataSource=ds.Tables
["client"].DefaultView;
MyDataGrid.DataBind();
}
</script>
<body style="FONT: 10pt verdana"
background="bg_blond.jpg">
<form runat="server">
<table width="95%">
<tr>

<td nowrap>Client ID</td>

<td width="163"><input type="text" id="client_id"
runat="server" NAME="client_id"></td>

<td nowrap>Address ID</td>

<td width="163"><input type="text" id="adr_id"
runat="server" NAME="adr_id"></td>

</tr>

<tr>

<td nowrap>Locale ID</td>

<td width="163"><input type="text" id="locale_id"
runat="server" NAME="locale_id"></td>

</tr>

<tr>

<td><hr size="3">

</td>

<td><hr size="3">

</td>

<td><hr size="3">

</td>

<td><hr size="3">

</td>

</tr>

<tr>

<td nowrap>Status</td>

<td width="163"><input type="text" id="status"
runat="server" NAME="status"></td>

<td nowrap>Start Date</td>

<td><input type="text" id="start_date"
runat="server" NAME="start_date">

<asp:CompareValidator Runat="server"
ID="startDateCompareValidator"
ControlToValidate="start_date" Display="Dynamic"

Operator="DataTypeCheck"
Type="Date" ErrorMessage="Must enter a valid date." />

<asp:RangeValidator Runat="server"
ID="startDateRangeValidator"
ControlToValidate="start_date" Display="Dynamic"

MinimumValue="2004-1-1"
MaximumValue="9999-12-31" Type="Date" ErrorMessage="Date
entered is out of range." />

</td>

</tr>

<tr>

<td nowrap>Currency Code</td>

<td><input type="text" id="currency"
runat="server" NAME="currency"></td>

<td nowrap>Expiration Date</td>

<td width="163"><input type="text" id="expir_date"
runat="server" NAME="expir_date">

<asp:CompareValidator Runat="server"
ID="exprDateCompareValidator"
ControlToValidate="expir_date" Display="Dynamic"

Operator="DataTypeCheck"
Type="Date" ErrorMessage="Must enter a valid date." />

<asp:RangeValidator Runat="server"
ID="exprDateRangeValidator" ControlToValidate="expir_date"
Display="Dynamic"

MinimumValue="2004-1-1"
MaximumValue="9999-12-31" Type="Date" ErrorMessage="Date
entered is out of range." />

</td>

</tr>

<tr>

<td></td>

<td width="163">

<input type="submit"
OnServerClick="AddClient_Click" value="Add Client"
runat="server"

ID="submit" NAME="submit">

</td>

</tr>

<tr>

<td colspan="2" align="center" width="295">

<span id="Message" runat="server"></span>

</td>

</tr>
</table>
<br>

<asp:DataGrid id="MyDataGrid" runat="server"
Width="800" BackColor="#ccccff" BorderColor="black"

ShowFooter="false" CellPadding="3" CellSpacing="1"
Font-Name="Verdana" Font-Size="8pt"
OnItemDataBound="MyDataGrid_ItemDataBound"

OnDeleteCommand="MyDataGrid_Delete"
OnEditCommand="MyDataGrid_Edit"
OnCancelCommand="MyDataGrid_Cancel"

OnUpdateCommand="MyDataGrid_Update"
DataKeyField="client_id" AutoGenerateColumns="False"
EnableViewState="true"

Visible="true">

<EditItemStyle BackColor="#33CCFF"></EditItemStyle>

<AlternatingItemStyle
BackColor="#99CCFF"></AlternatingItemStyle>

<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#0066FF"></HeaderStyle>

<Columns>

<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>

<asp:EditCommandColumn ButtonType="LinkButton"
UpdateText="Update" CancelText="Cancel" EditText="Edit">

<ItemStyle Wrap="False"></ItemStyle>

</asp:EditCommandColumn>

<asp:BoundColumn DataField="client_id"
SortExpression="client_id" ReadOnly="True"
HeaderText="client_id">

<ItemStyle Wrap="False"></ItemStyle>

</asp:BoundColumn>

<asp:BoundColumn DataField="adr_id"
SortExpression="adr_id"
HeaderText="adr_id"></asp:BoundColumn>

<asp:BoundColumn DataField="locale_id"
SortExpression="locale_id"
HeaderText="locale_id"></asp:BoundColumn>

<asp:BoundColumn DataField="status"
SortExpression="status"
HeaderText="status"></asp:BoundColumn>

<asp:BoundColumn DataField="start_date"
SortExpression="start_date"
HeaderText="start_date"></asp:BoundColumn>

<asp:BoundColumn DataField="expir_date"
SortExpression="expir_date"
HeaderText="expir_date"></asp:BoundColumn>

<asp:BoundColumn DataField="currency"
SortExpression="currency"
HeaderText="currency"></asp:BoundColumn>

</Columns>

</asp:DataGrid>
</form>
</body>
</HTML>
Nov 18 '05 #1
0 2108

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt | last post by:
I tried to display all html control types in the form. But it has run time error "object doesn't support this property or method" on document.write(obj.type); Even I do document.write('hello...
3
by: news.onetel.net.uk | last post by:
I and my friend Karl have spent literally all day trying to find out what is causing my error but we are zapped of any further functionality :) I have a form that adds news records. You select...
2
by: SmittyBroham | last post by:
Hello, I have a function that loops through 2 select lists and records the values of any hi-lighted options a user would have selected. It then sets 2 corresponding "hidden" form elements to the...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
4
by: Cylix | last post by:
Sample code of the problem: function inputOne() { alert('a'); } <input name="inputOne" id="inputOne" value="Warn" onclick="inputOne()"> The error is the object doesn't support this method.
5
by: John Olbert | last post by:
Subject: Error is Object doesn't support this property or method I am trying to pass a C# string under Vs2005 (Net2) to an Vb6 ActiveX Control. I get the following runtime error-- "Object...
8
by: Kevin Blount | last post by:
I'm tyring to access an object created by using a method from a third party API. The documentation tells me what object should be return, and the properties of that object, but when I try and...
3
by: Peachstone | last post by:
I'm using Windows XP and MS Access 2002. I am trying to write code in VB which is attached to a text control on a form called "Scripture1". I have another text control on the same form called...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.