Guids Are Not Very Guid! Updating In DetailsView,FormView (Object Must Implement IConvertible)
Dec 1, 2005
I've been playing around with the new data controls (DetailsView,FormView) and have been having problems when attempting to update a record that has a uniqueidentifier as its primary key.I get the error message:
Object must implement IConvertible. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object must implement IConvertible.I gather this is because there is a bug that has propagated from the beta version.One suggested work around is from http://64.233.183.104/search?q=cache:GDjA62POtgcJ:scottonwriting.net/sowBlog/archive/11162005.aspx+Implicit+conversion+from+data+type+sql_variant+to+uniqueidentifier+is+not+allowed.+Use+the+CONVERT+function+to+run+this+query.&hl=en
The crux of the problem, it appears, is that the <asp:Parameter> value for the uniqueidentifier field is, by default, set to Type=�Object�. To fix this, simply remove the Type property altogether. That is, change the SqlDataSource parameter setting from something like:
<asp:SqlDataSource ...> <InsertParameters> <asp:Parameter Name=�UserId� Type=�Object� /> ... </InsertParameters></asp:SqlDataSource>
to:
<asp:SqlDataSource ...> <InsertParameters> <asp:Parameter Name=�UserId� /> ... </InsertParameters></asp:SqlDataSource>
This change worked for me; once the Type was removed the exception ceased and the updates/inserts worked as expected.Unfortunately this only partially worked for me as while it is fine for deletes it won't work for updates.If anyone can help shed any light on this I would greatly appreciate it.CheersMark
View 28 Replies
ADVERTISEMENT
Feb 8, 2006
using (SqlConnection oConn = new SqlConnection(sConnection))
using (SqlCommand oCommand =
this.CreateSqlCommand("rcsp_employee_f_changerole.xml", oConn))
{
try { oConn.Open(); }
catch(Exception ex)
{
p_nErrorCode =
10;
p_sErrorMessage = "Error opening database connection during
RCEmployee.DBUpdate: " + ex.Message;
goto Failed;
}
oCommand.Parameters["@employeeid"].Value = p_gID;
oCommand.Parameters["@authorityid"].Value = p_gAuthorityID;
oCommand.Parameters["@role"].Value=sNewRole;
if (!ProcessNonQuery(oCommand,
sMethodName)) goto Failed;
Failed:
if (ErrorCode > 0) bReturn =
false;
oConn.Close();
}
}
return bReturn;
p_gID, p_gAuthorityID is of type guid.
sNewRole is of type string.
I get the error " Object must implement IConvertible at
oCommand.ExecuteNonQuery(); whihch is in the function if (!ProcessNonQuery(oCommand, sMethodName))
View 1 Replies
View Related
Oct 16, 2006
Using: VB.Net 2003, SQL Server 2000 and nText Column...
Examples: "Writing BLOB Values to a Database [Visual Basic]" and "Conserving Resources When Writing BLOB Values to SQL Server [Visual Basic]"
I modified the following code from the samples that were available in Help and MSDN. When my application reaches the ExecuteNonQuery statement it informs me that the Byte Array oDocument must implement IConvertible. I have even tried the extended version which uses a SQL Insert followed by UPDATETEXT with Pointers, and I get the same result with the Byte Array used in that example. My goal is to have Users Append certain documents to Proposals within my database, as I understand that is what I would be doing anyway if I used SharePoint.
Following the examples I have not trouble whatsoever reading an Image File from SQL Server 2000, and therefore I expect no trouble with nText Fields. I just cannot seem to insert Documents or Images via VB Code.
What is wrong with the examples that I cannot use the same code?
---- VB Code Follows ----
Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
Dim oSQLConnection As System.Data.SqlClient.SqlConnection
Dim oSQLCommand As System.Data.SqlClient.SqlCommand
Dim oSQLDataReader As System.Data.SqlClient.SqlDataReader
Dim oDocument() As Byte
Try
'Define the Initial Directory to be the "My Documents" Directory.
ofdAttachment.InitialDirectory = "My Documents"
'Filter for File of Word, PDF, and Text. This will suffice for now.
ofdAttachment.Filter = "Word Documents (*.doc)|*.doc|PDFs (*.pdf)|*.pdf|Text Files (*.txt)|*.txt"
'Show the Dialog to Open a File.
ofdAttachment.ShowDialog()
'If the User Selected a File then attempt to Add the Attachment.
If ofdAttachment.FileName <> String.Empty Then
'Read the Document into a Byte Array.
oDocument = GetDocumentInBytes(ofdAttachment.FileName)
'Define the Connection to the SQL Database.
oSQLConnection = New System.Data.SqlClient.SqlConnection("Persist Security Info=False;Integrated Security=SSPI;database=proposal_tracking;server=dbserverdbserver;")
'Attempt to Open the SQL Connection.
oSQLConnection.Open()
'Create a New SQL Command Object.
oSQLCommand = New System.Data.SqlClient.SqlCommand
'Assign the SQL Connection information to the SQL Command Object.
oSQLCommand.Connection = oSQLConnection
'Define the SQL Statement to Attach the Document.
oSQLCommand.CommandText = "INSERT INTO Documents (DocumentName, Document) VALUES (@DocumentName, @Document)"
oSQLCommand.CommandType = CommandType.Text
'Define the Parameters of the SQL Statement.
oSQLCommand.Parameters.Add("@DocumentName", SqlDbType.VarChar).Value = Mid(ofdAttachment.FileName, ofdAttachment.FileName.LastIndexOf("") + 2)
oSQLCommand.Parameters.Add("@Document", SqlDbType.NText, oDocument.Length).Value = oDocument
'Execut the SQL Statement. Resulting in an Error that states:
'Object must implement IConvertible.
oSQLCommand.ExecuteNonQuery()
If Not oSQLCommand Is Nothing Then
oSQLCommand.Dispose()
oSQLCommand = Nothing
End If
If Not oSQLConnection Is Nothing Then
oSQLConnection.Close()
oSQLConnection = Nothing
End If
End If
Catch sqlex As System.Data.SqlClient.SqlException
MsgBox(sqlex.Message)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Shared Function GetDocumentInBytes(ByVal strFilePath As String) As Byte()
Dim ofsDocumentReader As System.IO.FileStream = New System.IO.FileStream(strFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim obrDocumentReader As System.IO.BinaryReader = New System.IO.BinaryReader(ofsDocumentReader)
Dim oDocument() As Byte
Try
oDocument = obrDocumentReader.ReadBytes(CInt(ofsDocumentReader.Length))
obrDocumentReader.Close()
ofsDocumentReader.Close()
Return oDocument
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
View 1 Replies
View Related
Aug 9, 2006
i try to do a simple insert using SQLDataSource and a Stored Procedure
I try all night and always have this error
Object Must Implement IConvertible
I can’t understand where I wrong..
Looking around I understand is maybe a typecasting problema but I not find nothing more understeable..
Could someone tell me why Microsoft release this SQLdatasorce making more difficult a simple insert?
If someone could help me to fix this problem please
Here is the code
------------------------------------------------------------------------------------------------------------
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
SqlDataSource1.Insert()
Catch ex As Exception
Response.Write(ex.ToString)
Finally
SqlDataSource1.Dispose()
End Try
End Sub
------------------------------------------------------------------------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>"
InsertCommandType="StoredProcedure" InsertCommand="dbo.StoredProcedure1">
<InsertParameters>
<asp:ControlParameter ControlID="DropDownListCategory" Name="@CategoryID" PropertyName="SelectedValue"
Type="Int32" />
<asp:ControlParameter ControlID="DropDownListCategory" Name="@ModelNumber" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="txtModelName" Name="@ModelName" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtProductImage" Name="@ProductImage" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtUnitCost" Name="@UnitCost" PropertyName="Text"
Type="Decimal" />
<asp:ControlParameter ControlID="txtDescription" Name="@Description" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtWeight" Name="@Weight" PropertyName="Text" Type="Decimal" />
<asp:ControlParameter ControlID="txtDiscount" Name="@Discount" PropertyName="Text"
Type="Decimal" />
<asp:ControlParameter ControlID="chkIsActive" Name="@isActive" PropertyName="Checked"
Type="Boolean" />
<asp:ControlParameter ControlID="DropDownListAuthors" Name="@IDAuthor" PropertyName="SelectedItem"
Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
------------------------------------------------------------------------------------------------------------
ALTER PROCEDURE dbo.StoredProcedure1
@CategoryID int,
@ModelNumber nvarchar(50),
@ModelName nvarchar(50),
@ProductImage nvarchar(50),
@UnitCost money,
@Description varchar(500),
@weight money,
@IsActive bit,
@DiscountPerCent int,
@IDAuthor int
AS
INSERT INTO dbo.CMRC_Products (
CategoryID,
ModelNumber,
ModelName,
ProductImage,
UnitCost,
Description,
weight,
IsActive,
DiscountPerCent,
IDAuthor
)
VALUES (
@CategoryID,
@ModelNumber,
@ModelName,
@ProductImage,
@UnitCost,
@Description,
@weight,
@IsActive,
@DiscountPerCent,
@IDAuthor
)
SELECT @@IDENTITY as [NewID]
------------
View 4 Replies
View Related
Apr 6, 2008
still having problems... here is my code.. (NOTE: I have no code in my .aspx.cs ...maybe that is my problem)
<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage2.master" AutoEventWireup="true" CodeFile="dUsers.aspx.cs" Inherits="Admin_dUsers" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="SqlDataSource1" DataKeyNames="UserId" AutoGenerateDeleteButton="True" >
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT UserId, First, Last, Email, CreateDate, LastLoginDate, IsApproved, IsLockedOut FROM aspnet_Membership"
DeleteCommand="DELETE FROM aspnet_Membership WHERE [UserId] = @UserId"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" >
<DeleteParameters>
<asp:Parameter Name="UserId" Type="Int32"/>
</DeleteParameters>
</asp:SqlDataSource>
</asp:Content>
-------------------------------------------------------------
when i click the delete button... this error appears..
-------------------------------------------------------------
Server Error in '/mapuaResearch' Application.
Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object must implement IConvertible.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidCastException: Object must implement IConvertible.]
System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +2514354
System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +257
System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +657
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +529
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +176
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +912
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1067
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +215
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839
* i think i hav to have a code in my c# side.. but i have no idea how to do it.. can someone please help me!!! i really need it.. tnx a lot...
View 1 Replies
View Related
Dec 6, 2003
Hi,
I am trying to call a stored procedure to insert into my database. After I called Open(), it crashed on ExecuteNonQuery(). I get the following message.
Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Object must implement IConvertible.
Source Error:
Line 160:Try
Line 161:myConnection.Open()
Line 162:myCommand.ExecuteNonQuery()
Line 163:myConnection.Close()
What does this mean? If anyone encountered this error before, please let me know how to trace the error and fix it.
Thanks Gurus,
John
View 4 Replies
View Related
Feb 8, 2007
Hi
I am new to asp.net world. I have a page with two formviews bound to two sqldatsources. One datasource connects to sql database and other to access. The information from both the databases is quite similar. The default mode for formview1 is edittemplate and for formview2 it is itemtemplate. I want to give the user an option to update formview1 data based on information retrevied in formview2 on a click of a button.
I want to do this in code behind .cs file. I am not sure how can I access the values from formview templates e.g formview1.itemtemplate... etc?
Can anyone please suggest a way to acheive this?
Thanks
View 5 Replies
View Related
May 7, 2008
In my site, when a user registers, I need to create rows in additional tables besides aspnet_Users. So, I need to be able to pass the generated userId guid to subsequent SqlCommands. I'm having a terrible time with this. What's the correct way to set up a SqlParameter so that it will accept a guid? I keep getting this error: "Conversion failed when converting from a character string to uniqueidentifier."
I've tried creating the parameter both with and without a SqlDbType.
cmd.Parameters.AddWithValue(paramName, guid);
and
SqlParameter p = new SqlParameter(paramName);p.SqlDbType = SqlDbType.Guid;cmd.Parameters.Add(p);
and I get the same error either way.
Driving me nuts! Any help appreciated.
View 1 Replies
View Related
Jan 4, 2007
Hi, I am a beginner in ASP.NET 2.0
I am creating a simple blog website.
I am using a DataReader object to collect all of the entries in the database (in one full sweep) and then display them by adding rows to a table and populating them.
I would like to enable paging so that only 5 blog entries at a time are displayed. The user should be able to page backwards and forwards 5 at a time.
Please can somebody give me some ideas of how I should do this?
Should I read all of the data into some kind of list so that all of the data is then readily available? An arraylist or something?
I realise that the DataReader object reads in one continuous stream so I couldn't expect it to read backwards and forwards from the database.
I include a portion of my code below which reads the database.
Many thanks.
Dim objCommand As New SqlCommand objCommand.Connection = objConnection objConnection.Open() objCommand.CommandText = "SELECT BlogID, Date, Blog FROM BlogSite2_Blogs ORDER BY Date DESC"
Dim objReader As SqlDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
Dim dateDateTime As Date Dim strBlogEntry As String Dim intBlogID As Integer
Do While objReader.Read() intBlogID = objReader.GetValue(0) dateDateTime = objReader.GetDateTime(1) strBlogEntry = objReader.GetString(2)
CreateBlogRow(intBlogID, dateDateTime, strBlogEntry) Loop
objReader.Close()
View 3 Replies
View Related
Dec 28, 2007
Hi Guyz
it is taken from SQL2K5 SP2 readme.txt. Anyone have idea what to do to implement this ?
Our sp2 is failing. we suspect the above problem and researching it.we are running on default instance of SQL2K5 on win2003 ent sp2
"When you apply SP2, Setup upgrades system databases. If you have implemented restrictions on the ALTER DATABASE syntax, this upgrade may fail. Restrictions to ALTER DATABASE may include the following:
Explicitly denying the ALTER DATABASE statement.
A data definition language (DDL) trigger on ALTER DATABASE that rolls back the transaction containing the ALTER DATABASE statement.
If you have restrictions on ALTER DATABASE, and Setup fails to upgrade system databases to SP2, you must disable these restrictions and then re-run Setup."
thanks in advance.
View 4 Replies
View Related
Mar 6, 2007
I am updating data with sqlDatasource but it is inserting NULL, tell what I am missing <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
DefaultMode="Insert" Width="100%">
<InsertItemTemplate>
<table width="100%">
<tr>
<td style="width: 100px">
Name</td>
<td style="width: 100px">
<asp:TextBox ID="txtCategory" runat="server" Text='<%# Eval("CategoryName") %>'></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Parent</td>
<td style="width: 100px">
<asp:DropDownList ID="ddlParent" runat="server" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryID" Width="100%">
</asp:DropDownList></td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
<asp:Button ID="btnAdd" runat="server" Text="Add" CommandName="Insert"/></td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>"
SelectCommand="SELECT [CategoryID], [CategoryName], [CategoryMID] FROM [CMRC_Categories]"
DeleteCommand="DELETE FROM [CMRC_Categories] WHERE [CategoryID] = @CategoryID"
InsertCommand="INSERT INTO [CMRC_Categories] ([CategoryName], [CategoryMID]) VALUES (@CategoryName, @CategoryMID)"
UpdateCommand="UPDATE [CMRC_Categories] SET [CategoryName] = @CategoryName, [CategoryMID] = @CategoryMID WHERE [CategoryID] = @CategoryID">
<DeleteParameters>
<asp:Parameter Name="CategoryID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="CategoryMID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:FormParameter Name="CategoryName" Type="String" FormField="txtCategory" />
<asp:FormParameter Name="CategoryMID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource> Please suggest cheers
View 4 Replies
View Related
Oct 7, 2005
In the master database for a SQL Server instance I noticed the dt... objects (procedures, etc.) in create date of today about 7 minutes before I looked in sysobjects. No changes have been made to that instance for months. Also in other cases I noticed the same thing just different dates for each instance. Any ideas on why the dates would change?
View 1 Replies
View Related
Jun 6, 2006
Hi all,
We have sql sever 2000 as our backend database system. on the front, we have vb medical application screen for users to do the data entry.
for 7th screen, it is assoicated with table Case_Custom. user enter data througth 7th screen to populate Case_Custom table.
There is one column called Case_Custom.CaseID ( a foreign key to to parent table Cases) was populated automatically instead of user input.
However, I could not find which stored procedure, views or trigger or application code to populate this field? I have queried INFORMATION_SCHEMA.ROUTINES, dbo.syscomments and did not find anything updating Case_Custom.CaseID.
I have contacted our app vendor and have got any answer from them yet.
Any ideas?
Thanks,
Jane
View 1 Replies
View Related
Oct 31, 2007
Hello,I am creating a new database and I was advised to use Sequential Guids.I was reading some information and, as far as I understood, I can use NEWSEQUENTIALID. This can be used when I have a uniqueidentifier column as the key of a clustered index to avoid fragmentation during insert. Ok, so I use NEWSEQUENTIALID instead of NEWID.But I will use LINQ most of the time instead of Stored Procedures.So can I specify in my tables scripts to use Sequential Guids when, for example, a record is created? And am I right when using Sequential Guids?Here is a part of my code:-- Blogs ...
create table dbo.Blogs
(
BlogID uniqueidentifier not null
constraint PK_Blog primary key clustered,
Title nvarchar(400) null,
Description nvarchar(2000) null,
CreatedDate datetime null
)
-- Posts ...
create table dbo.Posts
(
PostID uniqueidentifier not null
constraint PK_Post primary key clustered,
BlogID uniqueidentifier not null,
AuthorID uniqueidentifier not null,
Title nchar(1000) null,
Body nvarchar(max) null,
UpdatedDate datetime not null,
IsPublished bit not null,
constraint FK_Posts_Blogs
foreign key(BlogID)
references dbo.Blogs(BlogID)
on delete cascade,
constraint FK_Posts_Users
foreign key(AuthorID)
references dbo.Users(UserID)
on delete cascade Thanks,Miguel
View 2 Replies
View Related
Sep 21, 2005
I'm really sorry if this is too OT but it is related to replication...
View 1 Replies
View Related
Feb 26, 2004
We're trying to set a new standard at my office, of using GUIDs as database ID fields - all new tables in all databases will have a GUID as the ID field, using the UniqueIdentifier data type.
The problem that we are running into, is that different applications interpret the UniqueIdentifier data type differently - ADO 2.x interprets it with the opening and closing { } braces. ADO.NET does not include the { and } in the GUID structure, SQL Server Query Analyzer does not include the { } braces, and SQL Server Enterprise Manage does include the { }
so we end up with results like this:
ADO 2.x: {012345678-abcd-ef01-2345-6789abcd}
ADO.NET: 012345678-abcd-ef01-2345-6789abcd
Query Analyzer: 012345678-abcd-ef01-2345-6789abcd
Enterprise Manager: {012345678-abcd-ef01-2345-6789abcd}
The problem with this is in two parts:
1) VB6 does not have a GUID structure or data type, so we are treating GUIDs as strings... but VB6 doesn't recognize "{012345678-abcd-ef01-2345-6789abcd}" and "012345678-abcd-ef01-2345-6789abcd" as the same string
2) when sending a URL link through an email, the { } braces break the link - in all email applications that we have tested. This include Groupwise 6, Groupwise 6.5, IPSwitch Web IMail, Outlook 2000, and Outlook Express (IE 6).
We're becoming very frustrated with the problems at hand, and need to know how others have worked around these problems. Please respond with any kind of advice or any real life situations where you have encountered this and found a solution, etc.
Thanks.
View 3 Replies
View Related
Feb 28, 2006
Hello,
I've been thinking about using GUIDs as primary keys within my application. One problem I have with this approach is that GUIDs generated with NEWID() are not sequential, and this can have a huge impact on insertion performance due to fragmented indexes. It would seem that NEWSEQUENTIALID() solves this issue, however it doesn't seem very practical to use this on SQL Server Mobile. With SQL Server, you can specify an OUTPUT clause for an INSERT statement, and using this, determine what the last inserted GUID was. There doesn't seem to be such an option in SQL Server Mobile, so how can I get the last generated GUID so that I can attach children records to my parent record? It's been suggested that you could use the MAX() function to get the latest GUID, but there is a problem with this approach - NEWSEQUENTIALID() guarantees that the GUIDs generated will be sequential for the machine generating them, but makes no guarantees about how this will fit in with GUIDs generated by other machines. It is entirely possible that GUIDs generated by a different machine will be larger than the latest one generated on the current machine, so using MAX() to determine the latest value doesn't seem like a valid option to me.
Does anybody have any ideas on tackling this problem? Any thoughts on the suitability of using GUIDs as the primary key for SQL Server Mobile devices in general?
Thanks,
Adrien.
View 1 Replies
View Related
Jan 18, 2006
Am I looking at a potential bug here or do I not understand the feature properly? I have an ExecuteSQL task that inserts into a table for logging and includes the System::PackageID as one of the values. It's stored in my table as a uniqueidentifier. When I set the output variable in Parameter Mappings tab of the Execute SQL task to VarChar, all works great. WHen I set it to GUID as the data type in that tab, it outputs a different GUID than the actual System::PackageID variable.
-- Brian
View 1 Replies
View Related
Jan 30, 2008
Are Guids good or bad? I've spoken to people who hate them in databases, but the db's I'm using right now all use them, so there must be *some* people out there who like them. I'm interested to know what other people think.
thanks!
View 6 Replies
View Related
Jul 1, 2003
I need gurus input on the pros and cons of Seeded(int) Identity colums vs. UniqueIdentifier(GUIDs) columns for my db design.
As I understand it, merging the data of 2 independent db's both using IDENTITY columns would be very hairy because of the possibility of overlap. GUIDs are much more likely to be unique across different servers.
What I'd like to hear from others are the other pros and cons of the situation. I of course understand the performance hit suffered at the hands of the GUID.
Thanks for your help!
View 29 Replies
View Related
Dec 14, 2006
Hi fellows ,
there is a senerio where i want to update GUIDS in columns "pubid" and "artid" generate in sysmergepubliction and sysmergeAricles respectivly in sqlserver 2005 ?
2nd is there any easy way to generate scripts of triggers of all replicated tables in subscriber at one .
View 1 Replies
View Related
Dec 11, 2007
hello,
I have several tables that have guids as their primary keys and the tables are related as follows:
Table1 - primary key = ServiceNo (Guid), Filter Key = CampaignNo
Table2 - primary key = CostBasisNo (Guid), Foreign Key = ServiceNo (from Table1)
Table3 - primary key = UserId, Foreign Key = ServiceNo (from table1)
Table4 - primary key = SourceServiceNo (Foreign Key from Table1), MemberServiceNo(Foreign Key from Table1)
what I need to do is copy all records from Table1 where CampaignNo = @CampaignNo and insert them into table1, this I can do easily but I will generate a new ServiceNo for each one and associated a new CampaigNo which is fine.
The problem comes in that I need to also copy the contents of Table2 = Table3 for all ServiceNos that have been copied from Table1 but insert the new Guid that will have been created when copying the rows in Table1
This is further compounded when I need to do the same to Table4 but this time I need to insert the newid's for SourceServiceNo and the related MemberServiceNo which all would have changed.
I haven't the first clue where to start with this task, do I need to use temporary tables, cursors? any help gratefully received, even if it's a pointer to the most efficient approach.
regards
View 4 Replies
View Related
Dec 18, 2007
Hi,I am using detailsview to update my database and got a question regarding datetime format. Here is part of my code:
<asp:TemplateField HeaderText="Project Deadline">
<EditItemTemplate>
<asp:TextBox ID="txtDeadline_edit" runat="server" Text='<%# Bind("pro_app_deadline") %>'></asp:TextBox>
<asp:CompareValidator ID="txtDeadlineedit_validator" runat="server" ErrorMessage="Not a valid date format" ControlToValidate="txtDeadline_edit" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
</EditItemTemplate>
<ItemTemplate><asp:Label ID="txtDeadline" runat="server" Text='<%# Eval("pro_app_deadline") %>'></asp:Label>
</ItemTemplate></asp:TemplateField>
Since the format of my parameter 'pro_app_deadline' is datetime, it get stored as YYYY-MM-DD hh:mm:ss in datebase. If I want to validate user's input like above way, it always fails since hh:mm:ss append to YYYY-MM-DD. My question is, is there some way I can avoid hh:mm:ss?
Thanks a lot!
View 2 Replies
View Related
May 14, 2006
Can someone please tell me what I am doing wrong...
I have a simple webform that has contains a GridView and a DetailsView. Once the GridView is populated the user simply selects a record from the list. The DetailsView is them populated with all of the data from the selected record.
The DetailsView is bound to a SQL DataSource/CustomerData. I have made sure that the DV control has the Edit/Update Command listed. The user can click the Edit button and successfully edit the fields but when the user clicks the "Update" button I am getting the following message.
Updating is not supported by data source 'CustomerData' unless UpdateCommand is specified
Why isnt the control handling the Update.
Many Thanks!!!!
T
View 4 Replies
View Related
Jun 9, 2007
Hi everybody,I have a little Problem with an update and Detailsview.I have 2 table (tblUser - uid,uName,rId) and (tblRole - rId, rDescription) In my update I don't want to use the roles id, I want to use the roles Description.Via sql I do a update the role to Admin like that UPDATE tblUser
SET rId =
(SELECT rId
FROM dbo.tblRoles
WHERE (rDescription = 'Admin')) But I don't get it to work for the detailsview update
View 4 Replies
View Related
Jul 23, 2007
i get Incorrect syntax near 'nvarchar'.Must declare the scalar variable "@BookingID".
Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'nvarchar'.Must declare the scalar variable "@BookingID".
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near 'nvarchar'.Must declare the scalar variable "@BookingID".] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857354 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734966 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 ...i am using the Edit feature of the detailsview, seems like the datatype is wrong? ID are int (in my DB, BookingID is int), and also its readonly it should not be updating in the first place right? --------------------------------Any way to debug whats in "new" values? ItemUpdating? how to do it?
View 3 Replies
View Related
Jun 9, 2008
Hi,
Can anyone tell me why my Update attempts are not working? Here is my code:
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
AutoGenerateEditButton="True" AutoGenerateRows="False" DataSourceID="SqlDataSource1"
DefaultMode="Edit">
<Fields>
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
</Fields>
</asp:DetailsView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringListings %>"
SelectCommand="SELECT [City] FROM [Listings]"
UpdateCommand="UPDATE [Listings] Set [City]=@City WHERE [ListingID]=@ListingGuid ">
<UpdateParameters>
<asp:Parameter Name="City" />
<asp:Parameter Name ="ListingGuid" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</div></form>
</body>
And here is my code behindProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ListingGuid = Request.QueryString("GUID")
End SubProtected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
Label1.Text = "updated"
Label2.Text = ListingGuidEnd Sub
Please let me know what I am doing wrong?
View 3 Replies
View Related
Mar 6, 2006
Hi
I have a Page with a DetailsView and SqlDataSource. When Editing the DetailsView the Sql;DataSource UpdateCommand does not seem to pick up the @parameters of the form fields. I have used OnItemUpdating to view all Keys/OldValues/NewValues passed into the UpdateCommand but nothing seems to be picked up.
When I place a value into UpdateCommand it updates correctly but does not when I use the form. At this stage I have simplified the code down to typical Master-Details Pages (Separate) using a QueryString to filter the SelectCommand. But nothing seems to work.
Please help! I have wasted so much time trying to resolve this and I am on deadline and need this to work.
Thanks
Dave
View 3 Replies
View Related
May 1, 2006
Hello
Am developing a web site using ASP.net 2.0. I have page to manage the employees information in term of viewing, inserting and updating. The problem is that the updating part doesn't work and it didn't give me any error messages.
My code is as following:
<%@ Page Language="VB" AutoEventWireup="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<script runat="server" >
Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs)
If (Not e.Exception Is Nothing) Then
ErrorMessageLabel.Text = "An error occured while entering this record. Please verify you have entered data in the correct format."
e.ExceptionHandled = True
End If
GridView1.DataBind()
End Sub
Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
GridView1.DataBind()
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub
Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As System.EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub
</script>
<body dir="rtl">
<form id="form1" runat="server">
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:warehouse DBConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:warehouse DBConnectionString2.ProviderName %>"
SelectCommand="SELECT DISTINCT [dep_Code], [dep_Name], [BRN_Code] FROM [Departments]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:warehouse DBConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:warehouse DBConnectionString2.ProviderName %>"
SelectCommand="SELECT DISTINCT [ID], [Name],[Position], [DEPT_Code] FROM [Employees]
where [DEPT_Code]=@dep_Name">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="dep_Name" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:warehouse DBConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:warehouse DBConnectionString2.ProviderName %>"
SelectCommand="SELECT DISTINCT [ID], [Authentication], [Name], [Password], [Position], [DEPT_Code], [Contact] FROM [Employees]
where [ID]=@ID "
UpdateCommand="UPDATE [Employees]
SET
[ID] = @ID,
[Authentication]=@Authentication,
[Name]=@Name,
[Password]=@Password,
[Position]=@Position,
[DEPT_Code]=@DEPT_Code,
[Contact]=@Contact
WHERE [ID] = @ID "
InsertCommand="INSERT INTO [Employees]
([ID], [Authentication], [Name], [Password], [Position], [DEPT_Code], [Contact])
Values (@ID, @Authentication, @Name, @Password, @Position, @DEPT_Code, @Contact) "
>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ID" Type="Int32" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Authentication" Type="Int16" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="Position" Type="String" />
<asp:Parameter Name="DEPT_Code" Type="Int32" />
<asp:Parameter Name="Contact" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Authentication" Type="Int16" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Password" Type="String" />
<asp:Parameter Name="Position" Type="String" />
<asp:Parameter Name="DEPT_Code" Type="Int32" />
<asp:Parameter Name="Contact" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
<br />
أختر القسم :
<asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource1" AutoPostBack="True"
DataTextField="dep_Name" runat="server" DataValueField="dep_Code" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<table >
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px; height: 154px" valign="top">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource2" AllowPaging="True" AllowSorting="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanged="GridView1_PageIndexChanged">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Position" HeaderText="Position" SortExpression="Position" />
<asp:BoundField DataField="DEPT_Code" HeaderText="DEPT_Code" SortExpression="DEPT_Code" Visible="False" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
</td>
<td style="width: 100px; height: 154px" valign="top">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ID" OnItemUpdated="DetailsView1_ItemUpdated"
DataSourceID="SqlDataSource3" Height="50px" Width="125px" AllowPaging="True" OnItemInserted="DetailsView1_ItemInserted">
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
<asp:BoundField DataField="Position" HeaderText="Position" SortExpression="Position" />
<asp:BoundField DataField="Contact" HeaderText="Contact" SortExpression="Contact" />
<asp:TemplateField HeaderText="Department" SortExpression="DEPT_Code" >
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("DEPT_Code") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
DataTextField="dep_Name" DataValueField="dep_Code" SelectedValue='<%# Bind("DEPT_Code") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource1"
DataTextField="dep_Name" DataValueField="dep_Code" SelectedValue='<%# Bind("DEPT_Code") %>'>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Authentication" SortExpression="Authentication">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("Authentication") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList4" runat="server" SelectedValue='<%# Bind("Authentication") %>'>
<asp:ListItem Text="Admin_User" Value="1" />
<asp:ListItem Text="Super_User" Value="2" />
<asp:ListItem Text="Normal_User" Value="3" />
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server" SelectedValue='<%# Bind("Authentication") %>'>
<asp:ListItem Text="Admin_User" Value="1" />
<asp:ListItem Text="Super_User" Value="2" />
<asp:ListItem Text="Normal_User" Value="3" />
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
</td>
</tr>
</table>
<asp:Label ID="ErrorMessageLabel" EnableViewState="false" runat="server" />
</form>
</body>
</html>
View 4 Replies
View Related
Feb 13, 2007
Hi,I'm trying to create a registration page that I've divided into multiple pages (first page for basic details, next page for address, etc.). I insert the record in the first page, and update it in the other pages. I pass the newly created ID to the other pages using the Page.PreviousPage property. In the second page, I have the SqlDataSource configured as "SELECT * FROM [Table] WHERE ID = ?", and the UpdateCommand is "UPDATE .... WHERE ID = ?". In Page_Load, I am updating the SelectCommand to "SELECT ... WHERE ID = " & intID, and the UpdateCommand similarly. The I do a dtlsvw.Databind()But when I go to the next page (the newly created ID is being passed properly), the update doesn't do anything. The new record doesn't contain the values in the detailsview. Can somebody help me out? Thanks,Wild Thing
View 2 Replies
View Related
Jul 30, 2007
For some reason I can't make the stars align. Could someone spot the problem here? I'm looking to select the Identity of my last inserted record in the code behind my DetailsView. Here are the relavent bits:
Stored Procedure:ALTER PROCEDURE usp_EW_INSERTMajor
@StartDate datetime, @Finishdate datetime, @ProjectName nvarchar(1000), @WorkCell nvarchar(1000),
@JobName nvarchar(1000), @PartName nvarchar(1000), @StatusID int, @ResponsibleID int, @FacilityID int
AS
Set nocount on
DECLARE @ProjectID int
/*This saves the bits to the Project table*/
INSERT INTO EW_Project (ProjectTypeID,FacilityID,StartDate,FinishDate,Status,EmployeeID)
VALUES(1,@FacilityID,@StartDate,@FinishDate,@StatusID,@ResponsibleID)
/*This saves the bits to the Major table*/
SET @ProjectID = SCOPE_IDENTITY()
INSERT INTO EW_MajorBasic(ProjectID,ProjectName,WorkCell,JobName,PartName)
VALUES (@ProjectID,@Projectname,@WorkCell,@JobName,@PartName)
Set nocount off
SELECT @ProjectID as ProjectID
SQLDataSource<asp:SqlDataSource ID="ProjectData" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="usp_EW_GETMajorBasic"
SelectCommandType="StoredProcedure"
UpdateCommand="usp_EW_UPDATEMajorBasic"
InsertCommand="usp_EW_INSERTMajor"
InsertCommandType="StoredProcedure"
UpdateCommandType="StoredProcedure"
DeleteCommand="DELETE FROM EW_Project WHERE ProjectID = @ProjectID"
>
<UpdateParameters>
<asp:Parameter Name="ProjectID" Type="Int32" />
<asp:Parameter Name="StartDate" Type="DateTime" />
<asp:Parameter Name="Finishdate" Type="DateTime" />
<asp:Parameter Name="ProjectName" Type="String" />
<asp:Parameter Name="WorkCell" Type="String" />
<asp:Parameter Name="JobName" Type="String" />
<asp:Parameter Name="PartName" Type="String" />
<asp:Parameter Name="StatusID" Type="Int32" />
<asp:Parameter Name="ResponsibleID" Type="Int32" />
<asp:CookieParameter CookieName="EW_FacilityID" Name="FacilityID" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="StartDate" Type="DateTime" />
<asp:Parameter Name="Finishdate" Type="DateTime" />
<asp:Parameter Name="ProjectName" Type="String" />
<asp:Parameter Name="WorkCell" Type="String" />
<asp:Parameter Name="JobName" Type="String" />
<asp:Parameter Name="PartName" Type="String" />
<asp:Parameter Name="StatusID" Type="Int32" />
<asp:Parameter Name="ResponsibleID" Type="Int32" />
<asp:CookieParameter CookieName="EW_FacilityID" Name="FacilityID" />
</InsertParameters>
<SelectParameters>
<asp:Parameter Name="ProjectID" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ProjectID" />
</DeleteParameters>
</asp:SqlDataSource>
DetailsView<asp:DetailsView
ID="DetailsView1"
runat="server"
AutoGenerateRows="False"
DataKeyNames="ProjectID"
DataSourceID="ProjectData"
SkinID="SimpleDetailsView"
OnItemDeleted="ProjectData_Deleted"
OnItemInserted="DetailsView1_ItemInserted">
Code-Behind: Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
Dim newID As Integer = e.Values("ProjectID")
testlabel.Text = newID
End Sub
To be clear, everything is working. When I come to this page with an ID, the records display fine (Select works). The Update and Delete work just fine. The Insert works fine too. It's just that the ItemInserted part does not want to grab the ProjectID. Specifically, testlabel displays a Zero.
View 2 Replies
View Related
May 5, 2008
Hi all,I want to be able to implement what the following site shows in regards to dynamically displaying Data views of various types: http://quickstarts.asp.net/QuickStartv20/aspnet/samples/data/GridViewMasterDetails_vb.aspx I follow everything to the 'T' but for some reason all my data views are showing even before any initial selection is made in the drop down. How can I have certain grids appear only after a selection from another control has been made?Thanks in advance,Nick
View 1 Replies
View Related
Mar 20, 2008
I have been stuck on this problem for over a week, and have ripped out about all of my hair, so here it goes.
I am working on a portfolio on a website that administrators are allowed to update, but the public may only view....easy enough? The grid has three parameters; CatID, Descrip, and Pic - as seen below.
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NORTHWNDConnectionString %>"
SelectCommand="SELECT [CatID], [Descrip], [Pic] FROM [Categories]"
UpdateCommand="UPDATE Categories SET Descrip = @Descrip, Pic = @Pic WHERE CatID = @CatID"
DeleteCommand="DELETE FROM Categories WHERE CatID = @CatID"
InsertCommand="INSERT INTO [Categories] ([CatID], [Descrip], [Pic]) VALUES (@CatID, @Descrip, @Pic)" >
<DeleteParameters>
<asp:Parameter Name="CatID" Type="String" />
<asp:parameter Name="Descrip" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Descrip" />
<asp:parameter Name="Pic" />
<asp:parameter Name="CatID" Type="String" />
</UpdateParameters>
<insertparameters>
<asp:parameter Name="CatID" Type="String" />
<asp:parameter Name="Descrip" Type="String" />
<asp:parameter Name="Pic" Type="String"/>
</insertparameters>
</asp:SqlDataSource>
The first this I am not sure of, is whether Pic should be a String or not.
Basically I am using Detailsview for the administrator to update, and the gridview for the public view.
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" DataKeyNames="CatID" HeaderText = "Portfolio"
DataSourceID="SqlDataSource2" Height="50px"
Width="300px" Font-Size = "14px" HeaderStyle-Font-Size="Larger" HeaderStyle-BackColor ="#27437D" HeaderStyle-ForeColor = "White"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical">
<footerstyle backcolor="#CCCCCC" forecolor="Black" />
<rowstyle backcolor="#EEEEEE" forecolor="Black" />
<pagerstyle backcolor="#999999" forecolor="Black" horizontalalign="Center" />
<Fields>
<asp:boundfield DataField="CatID" HeaderText="Building/Job Name" ReadOnly="True" SortExpression="CatID">
</asp:boundfield>
<asp:boundfield DataField="Descrip" HeaderText="Description" SortExpression="CompanyName">
</asp:boundfield>
<asp:TemplateField HeaderText="Picture">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Pic")%>' ></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Pic")%>' ></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Pic") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:commandfield ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True">
</asp:commandfield>
</Fields>
<HeaderStyle BackColor="#27437D" Font-Size="Larger" ForeColor="White"></HeaderStyle>
<alternatingrowstyle backcolor="#DCDCDC" />
</asp:DetailsView>
And my Gridview...
<asp:GridView ID= "GridView1" runat="server" DataSourceID="SqlDataSource2" AllowSorting="True" BackColor="White" CellPadding="3" Caption = "Portfolio"
Font-Size ="14px" BorderColor="#999999"BorderStyle="None"BorderWidth="1px"GridLines="Vertical"AutoGenerateColumns="False">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" Font-Size = "Small" ForeColor="Black" />
<columns>
<asp:boundfield DataField="CatID" HeaderText="Building/Job Name"></asp:boundfield>
<asp:boundfield DataField="Descrip" HeaderText="Description"></asp:boundfield>
<asp:TemplateField HeaderText="Picture">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" text='<%# Eval("Pic") %>'
></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl= '<%# Eval("Pic") %>' />
</ItemTemplate>
</asp:TemplateField>
</columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#27437D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
Now as I was looking around on the web I saw many people converting the path of the image to binary and the casting it to the DB, and likewise retrieving it from the DB as binary and converting it to an image, the problem is, I don't know how to do this.
Any help to ease my troubles is apprechiated greatly.
Edit: Also I am not totally sure what the '<%Eval("Pic") %>' is doing, it was autofilled for me.
Edit again: Another thing, if I replace any of the ImageUrl to an image path on the computer it does fill the space in the gridview/detailsview. However, with both cases I get a Operand type clash: nvarchar is incompatible with image error.
View 1 Replies
View Related