D
Danielle
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>
<asparameter Name="Contactame" Type="string" />
<asparameter Name="ContactEmail" Type="string" />
<asparameter Name="ContactPhone" Type="string" />
<asparameter 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_IncidentsConnectionString %>"
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>
<asparameter Name="Contactame" Type="string" />
<asparameter Name="ContactEmail" Type="string" />
<asparameter Name="ContactPhone" Type="string" />
<asparameter Name="Guid" Type="string" />
</DeleteParameters>
</asp:SqlDataSource>
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>
<asparameter Name="Contactame" Type="string" />
<asparameter Name="ContactEmail" Type="string" />
<asparameter Name="ContactPhone" Type="string" />
<asparameter 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_IncidentsConnectionString %>"
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>
<asparameter Name="Contactame" Type="string" />
<asparameter Name="ContactEmail" Type="string" />
<asparameter Name="ContactPhone" Type="string" />
<asparameter Name="Guid" Type="string" />
</DeleteParameters>
</asp:SqlDataSource>