473,326 Members | 2,148 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,326 software developers and data experts.

Errors with Update and Delete functions of gridview control

Hello all -

Thank you in advance for any help you are able to provide.

I am populating a gridview from a stored procuedure. The returned data
is a name, phone number, email and guid of a contact in our database.

I also need to use the Edit and Delete funtions in the gridview.
Neither seems to be working as intended.

DeleteCommand="delete from contactTable where Name = @ContactName and
Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_ResourceGuid AS varchar(36)) = @Guid)"

When I try to delete a contact, I get this error

System.Data.SqlClient.SqlException: Must declare the scalar variable
"@ContactName".

So, I added the Delete Parametres:

<DeleteParameters>
<asp:Parameter Name="Contactame" Type="string" />
<asp:Parameter Name="ContactEmail" Type="string" />
<asp:Parameter Name="ContactPhone" Type="string" />
<asp:Parameter Name="Guid" Type="string" />
</DeleteParameters>

Now, when I try to delete, I get this:

System.InvalidCastException: Object must implement IConvertible.

The strange thing is, I am able to Update without having the
parameters specified using this

UpdateCommand="update Altiris.dbo.Inv_Current_Allowed_Contacts SET
Name = @ContactName, Email = @ContactEmail, Phone = @ContactPhone
WHERE (CAST(_ResourceGuid AS varchar(36)) = @Guid)"

but once I add in a set of UpdateParamters similar to the parameters
indicated above I get the IConvertible error again.

I'm coding in VS Web Developer 2005. The full code for the gridview
control (with names changed to protect the innocent) is below. By
the way, I am showing the footer in advance of implementing an insert
function...

Thanks-
Danielle

<asp:GridView ID="gdContacts" runat="server"
AutoGenerateColumns="False"
AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True"
DataSourceID="sqlContactInfo"
DataKeyNames="Guid"
ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="Contact Name"
SortExpression="ContactName">
<EditItemTemplate>
<asp:TextBox ID="txtContactName"
runat="server" Text='<%# Bind("ContactName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactName" runat="server"
Text='<%# Bind("ContactName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Email"
SortExpression="ContactEmail">
<EditItemTemplate>
<asp:TextBox ID="txtContactEmail"
runat="server" Text='<%# Bind("ContactEmail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactEmail" runat="server"
Text='<%# Bind("ContactEmail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Phone"
SortExpression="ContactPhone">
<EditItemTemplate>
<asp:TextBox ID="txtContactPhone"
runat="server" Text='<%# Bind("ContactPhone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactPhone" runat="server"
Text='<%# Bind("ContactPhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="btnInsert" runat="server"
CommandName="Insert" Text="Insert" />
</FooterTemplate>
<FooterStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Guid"
SortExpression="Guid" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Guid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<
%# Bind("Guid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Black" ForeColor="White" />
<AlternatingRowStyle BackColor="#FFE16D" />
</asp:GridView>
<asp:SqlDataSource ID="sqlContactInfo" runat="server"
ConnectionString="<%$
ConnectionStrings:Altiris_IncidentsConnectionStrin g %>"
SelectCommand="usp_sp"
SelectCommandType="StoredProcedure"
UpdateCommand="update contactTable Contacts SET Name =
@ContactName, Email = @ContactEmail, Phone = @ContactPhone WHERE
(CAST(_ResourceGuid AS varchar(36)) = @Guid)"
DeleteCommand="delete from contactTable where Name =
@ContactName and Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_ResourceGuid AS varchar(36)) = @Guid)" >
<SelectParameters>
<asp:QueryStringParameter Name="agreementGuid"
QueryStringField="agreementGuid" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Contactame" Type="string" />
<asp:Parameter Name="ContactEmail" Type="string" />
<asp:Parameter Name="ContactPhone" Type="string" />
<asp:Parameter Name="Guid" Type="string" />
</DeleteParameters>

</asp:SqlDataSource>
Jun 27 '08 #1
2 2458
Daniele,

DeleteCommand="delete from contactTable where Name = @ContactName and
Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_ResourceGuid AS varchar(36)) = @Guid)"

Where X=X is forever equal, have a look at your code, in my idea you oversee
something.

I would concatinate the paramters to one string in your place. You get
always errors doing it like that, but that is not the main problem.

Cor

"Danielle" <wx****@aol.comschreef in bericht
news:ff**********************************@26g2000h sk.googlegroups.com...
Hello all -

Thank you in advance for any help you are able to provide.

I am populating a gridview from a stored procuedure. The returned data
is a name, phone number, email and guid of a contact in our database.

I also need to use the Edit and Delete funtions in the gridview.
Neither seems to be working as intended.

DeleteCommand="delete from contactTable where Name = @ContactName and
Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_ResourceGuid AS varchar(36)) = @Guid)"

When I try to delete a contact, I get this error

System.Data.SqlClient.SqlException: Must declare the scalar variable
"@ContactName".

So, I added the Delete Parametres:

<DeleteParameters>
<asp:Parameter Name="Contactame" Type="string" />
<asp:Parameter Name="ContactEmail" Type="string" />
<asp:Parameter Name="ContactPhone" Type="string" />
<asp:Parameter Name="Guid" Type="string" />
</DeleteParameters>

Now, when I try to delete, I get this:

System.InvalidCastException: Object must implement IConvertible.

The strange thing is, I am able to Update without having the
parameters specified using this

UpdateCommand="update Altiris.dbo.Inv_Current_Allowed_Contacts SET
Name = @ContactName, Email = @ContactEmail, Phone = @ContactPhone
WHERE (CAST(_ResourceGuid AS varchar(36)) = @Guid)"

but once I add in a set of UpdateParamters similar to the parameters
indicated above I get the IConvertible error again.

I'm coding in VS Web Developer 2005. The full code for the gridview
control (with names changed to protect the innocent) is below. By
the way, I am showing the footer in advance of implementing an insert
function...

Thanks-
Danielle

<asp:GridView ID="gdContacts" runat="server"
AutoGenerateColumns="False"
AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True"
DataSourceID="sqlContactInfo"
DataKeyNames="Guid"
ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="Contact Name"
SortExpression="ContactName">
<EditItemTemplate>
<asp:TextBox ID="txtContactName"
runat="server" Text='<%# Bind("ContactName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactName" runat="server"
Text='<%# Bind("ContactName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Email"
SortExpression="ContactEmail">
<EditItemTemplate>
<asp:TextBox ID="txtContactEmail"
runat="server" Text='<%# Bind("ContactEmail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactEmail" runat="server"
Text='<%# Bind("ContactEmail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Phone"
SortExpression="ContactPhone">
<EditItemTemplate>
<asp:TextBox ID="txtContactPhone"
runat="server" Text='<%# Bind("ContactPhone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactPhone" runat="server"
Text='<%# Bind("ContactPhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="btnInsert" runat="server"
CommandName="Insert" Text="Insert" />
</FooterTemplate>
<FooterStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Guid"
SortExpression="Guid" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Guid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<
%# Bind("Guid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Black" ForeColor="White" />
<AlternatingRowStyle BackColor="#FFE16D" />
</asp:GridView>
<asp:SqlDataSource ID="sqlContactInfo" runat="server"
ConnectionString="<%$
ConnectionStrings:Altiris_IncidentsConnectionStrin g %>"
SelectCommand="usp_sp"
SelectCommandType="StoredProcedure"
UpdateCommand="update contactTable Contacts SET Name =
@ContactName, Email = @ContactEmail, Phone = @ContactPhone WHERE
(CAST(_ResourceGuid AS varchar(36)) = @Guid)"
DeleteCommand="delete from contactTable where Name =
@ContactName and Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_ResourceGuid AS varchar(36)) = @Guid)" >
<SelectParameters>
<asp:QueryStringParameter Name="agreementGuid"
QueryStringField="agreementGuid" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Contactame" Type="string" />
<asp:Parameter Name="ContactEmail" Type="string" />
<asp:Parameter Name="ContactPhone" Type="string" />
<asp:Parameter Name="Guid" Type="string" />
</DeleteParameters>

</asp:SqlDataSource>
Jun 27 '08 #2
use the names as DeleteCommand="delete from contactTable where Name = @Name
and
Email = @Email and Phone = @Phone "

i mean map the names correctly to the field names.

"Danielle" <wx****@aol.comwrote in message
news:ff**********************************@26g2000h sk.googlegroups.com...
Hello all -

Thank you in advance for any help you are able to provide.

I am populating a gridview from a stored procuedure. The returned data
is a name, phone number, email and guid of a contact in our database.

I also need to use the Edit and Delete funtions in the gridview.
Neither seems to be working as intended.

DeleteCommand="delete from contactTable where Name = @ContactName and
Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_ResourceGuid AS varchar(36)) = @Guid)"

When I try to delete a contact, I get this error

System.Data.SqlClient.SqlException: Must declare the scalar variable
"@ContactName".

So, I added the Delete Parametres:

<DeleteParameters>
<asp:Parameter Name="Contactame" Type="string" />
<asp:Parameter Name="ContactEmail" Type="string" />
<asp:Parameter Name="ContactPhone" Type="string" />
<asp:Parameter Name="Guid" Type="string" />
</DeleteParameters>

Now, when I try to delete, I get this:

System.InvalidCastException: Object must implement IConvertible.

The strange thing is, I am able to Update without having the
parameters specified using this

UpdateCommand="update Altiris.dbo.Inv_Current_Allowed_Contacts SET
Name = @ContactName, Email = @ContactEmail, Phone = @ContactPhone
WHERE (CAST(_ResourceGuid AS varchar(36)) = @Guid)"

but once I add in a set of UpdateParamters similar to the parameters
indicated above I get the IConvertible error again.

I'm coding in VS Web Developer 2005. The full code for the gridview
control (with names changed to protect the innocent) is below. By
the way, I am showing the footer in advance of implementing an insert
function...

Thanks-
Danielle

<asp:GridView ID="gdContacts" runat="server"
AutoGenerateColumns="False"
AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True"
DataSourceID="sqlContactInfo"
DataKeyNames="Guid"
ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="Contact Name"
SortExpression="ContactName">
<EditItemTemplate>
<asp:TextBox ID="txtContactName"
runat="server" Text='<%# Bind("ContactName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactName" runat="server"
Text='<%# Bind("ContactName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Email"
SortExpression="ContactEmail">
<EditItemTemplate>
<asp:TextBox ID="txtContactEmail"
runat="server" Text='<%# Bind("ContactEmail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactEmail" runat="server"
Text='<%# Bind("ContactEmail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Phone"
SortExpression="ContactPhone">
<EditItemTemplate>
<asp:TextBox ID="txtContactPhone"
runat="server" Text='<%# Bind("ContactPhone") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactPhone" runat="server"
Text='<%# Bind("ContactPhone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="btnInsert" runat="server"
CommandName="Insert" Text="Insert" />
</FooterTemplate>
<FooterStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Guid"
SortExpression="Guid" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Guid") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<
%# Bind("Guid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Black" ForeColor="White" />
<AlternatingRowStyle BackColor="#FFE16D" />
</asp:GridView>
<asp:SqlDataSource ID="sqlContactInfo" runat="server"
ConnectionString="<%$
ConnectionStrings:Altiris_IncidentsConnectionStrin g %>"
SelectCommand="usp_sp"
SelectCommandType="StoredProcedure"
UpdateCommand="update contactTable Contacts SET Name =
@ContactName, Email = @ContactEmail, Phone = @ContactPhone WHERE
(CAST(_ResourceGuid AS varchar(36)) = @Guid)"
DeleteCommand="delete from contactTable where Name =
@ContactName and Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_ResourceGuid AS varchar(36)) = @Guid)" >
<SelectParameters>
<asp:QueryStringParameter Name="agreementGuid"
QueryStringField="agreementGuid" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Contactame" Type="string" />
<asp:Parameter Name="ContactEmail" Type="string" />
<asp:Parameter Name="ContactPhone" Type="string" />
<asp:Parameter Name="Guid" Type="string" />
</DeleteParameters>

</asp:SqlDataSource>

Jun 27 '08 #3

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

Similar topics

3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
4
by: drakuu | last post by:
Hello there, I have DataGrid with some records and I would like to edit it right in the datagrid using the built in commands. I can't figure out a way to pass to the SQL query the record ID...
0
by: Terence | last post by:
Hi, I have a web user control which includes a gridview and a sqldatasource. It also has a property called TableName which is used to populate the gridview. However, i'm running into a problem...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
3
by: tarscher | last post by:
Hi all, I have a grid that contains 7 columns from 3 tables (3 unique keys, 4 normal fields). I show this 7 columns on the gridview. I now want to add edit and delete functionality. This should...
3
by: pvong | last post by:
VB.NET How do you change a gridview from Update mode to normal mode? I'm usually dealing for Formviews and there is a ChangeMode option but I don't see one for Gridviews.
5
by: cmrchs | last post by:
Hi, I'm trying out Databinding to a Data Acces Layer using a ObjectDataSource-control The Update works fine but the Delete-method doesn't. when debugging I see that my productID-parameter is...
0
by: cmrchs | last post by:
Hi, I'm trying out Databinding to a Data Acces Layer using a GridView and ObjectDataSource-control The Update works fine but the Delete-method doesn't ??? <asp:GridView ID="GridView1"...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.