DataSource Controls :: Insert Row Using Guid From Querystring?
Apr 2, 2010
I have a page with a gridview that is populated depending upon the value of the querystring passed to it - there is a one-to-many relationship between Jobs and Locations respectively (one job can have many locations), and the gridview is a list of Locations that are associated with a particular Job. So far so good.
I have a DetailsView below whose DefaultMode is Insert to add a new location, though I can't seem to capture the JobId (guid) from the querystring. I've tried the following code on the Datasource's Inserting event:
[Code]....
but on both occasions I get the same error: Foreign Key constraint broken on JobId field. It seems that the querystring is not being passed to the datasource for inclusion in the insert.
View 2 Replies
Similar Messages:
Apr 23, 2010
I have an SQLSiteMapProvider that needs a unique URL and have not got the smarts to work out how to get the provider to do the work so for now I thought I would just add the data to the DB then edit the URL with the ID. I can't do this on the first insert as I do not know the ID as it is an auto generated Primary Key
I tried to us the PostBackURL to go to a 2nd Page that got the New ID and added it to the end of the already known URL "Page.aspx?ID=" but apparently you can't do that as I found out (This would have been a masive hack to the problem I know but it would have got around it issue of for now)
this is how I guessed it would work
Insert Data with URL "Page.aspx?ID=" and more data.... Then Get New ID and update URL to have the ID on the end ie: Page.aspx?ID=99
View 7 Replies
Oct 4, 2010
trying to pass a guid value to querystring - it should take the guid value from one page to another. i get an error: value cannot be null, parameter name: g. so my guid value is not being pass to my second page. below is code:
Page one:
static Guid g = Guid.Empty;
public static string userID = g.ToString();
string userName = string.Empty;
[code]...
View 2 Replies
Jun 14, 2010
I am trying to retrieve a Guid from the database but my application just isnt having it. I have a field in the database called "LoginUserId" and it is of type "uniqueidentifier".In my User Model I have:
[Code]....
I keep getting the error: Specified cast is not valid.
View 2 Replies
Mar 26, 2011
I'm using ASP.Net/C# and I have a form that allows people to add information into a table and along with it I want to collect the Current Users GUID and insert it.
I have a field setup (UserID) as a unique identifier and I have the following code:
protected void Page_Load(object sender, EventArgs e)
{
MembershipUser currentUser = Membership.GetUser();
Guid temp = (Guid)(Membership.GetUser(User.Identity.Name).ProviderUserKey);
Guid @currentUserID = temp;
}
SqlConnection con = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True");
SqlCommand cmd;
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("insert into Accom (UserID) values('" + @currentUserID + "')", con);
cmd.ExecuteNonQuery();
}
I basically want to link the variable to the Database how as the above gives errors.
View 4 Replies
Feb 10, 2011
I'm creating a web project for one of my uni modules using Visual studio 2010. I'm using asp.net membership and have all of my sql-server tables set up correctly (I'm pretty sure).
I have a form that I have created myself that inserts into the database using sqlDataSource.insert(). I had some problems initially with not being able to insert any data into the table at all, but I have cleared that up.
My problem now is that I need to insert the currently logged in user's userID into one of the columns of the table. But every time I hit the submit button, I am told I cannot insert null values in the userID column.
I can retrieve the userID using this snippet:
[Code]....
This is the code behind for the page:
[Code]....
As you can see it is a bit of a mess, I've been frantically trying different variations, as I need to catch up a little with other uni modules.
Here is my SQLDataSource from the .aspx page, The controlparameters work fine for the other data I am inserting. maybe the <asp:parameter name="userID" /> is wrong?
[Code]....
I'm relatively new to vb, and I come from a html & css background.
View 1 Replies
Jun 3, 2010
I am trying to get the 'userid' of the logged in user using the code below:
"MembershipUser myObject = Membership.GetUser();
String userId = myObject.ProviderUserKey.ToString();"
and later using it as a parameter to the stored procedure.
The logic here is, the user should login first in order to retrieve his/her album. when the user is logged in, im retrieving the 'userid' and using it as parameter to load the corresponding album from the database.
when i login and open the albumpage, im end up with this exception:
"Failed to convert parameter value from a String to a Guid".
What could be the reason and how can i avoid this exception.
by the way im using the aspnet_Users table's userid field.
View 7 Replies
Dec 14, 2010
I am workining in vb.net and sql. In DB have a uniqueidentifier field and want to insert in it,
When try to send data, some thing parameter: ByVal value as GUID
In the query : '"& Value &"' then errors occurs " Operator & not define or supporting and System.GUID "
If do like that : '"& CAST(Value as uniqueidentifier) &"' then Says CAST undefined same with Convert.
View 3 Replies
Dec 12, 2010
I'm trying to insert userid that is a System.Guid into an additional table into the same userid field that is uniqueidentifier. It seems as it cannot insert the System.Guid type there wether I'm passing it directly as the System.Guid or as a String then converting.
<System.ComponentModel.DataObjectMethodAttribute _
(System.ComponentModel.DataObjectMethodType.Insert, True)> _
Public Function InsertUserInterests( _
ByVal strUserId As String, ByVal strCode As String) _
As Boolean
Dim userInter As New DS1.tblUserInterestsDataTable
Dim userInterRow As DS1.tblUserInterestsRow = userInter.NewtblUserInterestsRow
Dim ug As System.Guid = New Guid(strUserId)
userInterRow.UserId = ug ' This didn't go through I beleive
userInterRow.InterestCode = strCode
userInter.AddtblUserInterestsRow(userInterRow)
Dim rowsAffected As Integer = Adapter.Update(userInter)
Return rowsAffected = 1
End Function
View 3 Replies
Feb 19, 2010
I am attempting to use SqlBulkCopy to import data from an XML document. I receive the following error when executing WriteToServer: Invalid cast from 'System.String' to 'System.Guid'
View 1 Replies
Jan 12, 2010
I am trying to pass in as an insert parameter for SQLds2 the scope_identity of the insert of SQLds1.
Exception Details: System.InvalidOperationException: Error executing 'InsertCommand' in SqlDataSource 'SqlDataSource1'. Ensure the command accepts the following parameters: @Name1, @NewId
[Code]....
View 4 Replies
Aug 12, 2010
I do have a details view, which insert data to a database table using SQL Datasource. Now i need the data to be inserted in to 2 tables instead of one.
View 1 Replies
Mar 6, 2010
I am using 1 textbox with a Ajax Calendar extender to allow my user's to select a date graphically (exp: 12/15/2009). I have another textbox for the hour and minutes in military time(exp: 15:30). I think i have the code to grab the data from the 2 textbox's and combine them to be inserted into the field (exp: 12/15/2009 15:30). Here is my insert code for the Field:
[Code]....
However unless I make all the fields Nullable the insert fails, on top of that none of the other field that I have selected on the Detailsview Insert or Edit are inserted into there fields. Half of my fields have to be non-null values. So how do I fix this?
I can supply additional vb code and the aspx code if needed.
This is the error I'm getting: Cannot insert the value NULL into column 'Operation_type', table '/GAOSDB.MDF.dbo.BC_Perf_Log'; column does not allow nulls. INSERT fails. The statement has been terminated.'
This is the first non-null column.
I need to get this figured out because I have 30 other web pages that will be utilizing the same approach.
View 4 Replies
Jun 30, 2010
Conseptually what I'm doing is simple, and technically it may even be simple, but I'm still rusty. Here's what I'm trying to do:
I have a webform that allows the user to enter a new record, and in there I have also included a couple FileUpload controls. Upon clicking the "Save" button, I'm saving the details entered into one table (ITEMS), and also inserting the FileUpload details (path, id, upload_user) into another table ATTACHMNTS). Because one ITEM can have many attachments, I needed to split the tables up. So on save, I need to save the ITEM, save the ATTACHMENT, and then also put the ITEM_ID in the ATTACHMENT table. I'm second guessing myself because I think all I'd have to do is after I do the ITEM insert, do a SELECT MAX on the ITEM table and hold the newest (MAX) id in a variable and then use it in the ATTACHMENTS update. I'm not 100% on this because there IS a chance that someone else could save a few milliseconds later and I'll link the wrong ITEM. See my delima?
View 7 Replies
Dec 15, 2010
I have a project that I was using Access for but now find I have to change to SQL Express. Well I have no big problem with that but I now find that the SQL Statement I have been using was for OLE and does not work in SQL/Express. I am not even sure anymore if I can dump the entire CSV file in at one time? The statement I was using is below.
[Code]....
Here is my problem. What is the INSERT statement to insert a complete flat (CSV) into SQL Express? OR what method can I use to preform this task?
View 2 Replies
Sep 23, 2010
I have an ODS control populating a Telerik grid. The ODS definition is pretty simple. It's set to call a method on a static class that has one parameter (entityID). I set this parameter in the OnSelecting event. When I test this, the world is a happy place and all is fine.
Then, I pass a query string to the page (which sets various unrelated values for the page, we'll say parameters X and Y). The page call's Telerik's radgrid.Rebind() event. When this happens, an error is throw from the ODS saying that the underlying method (the static data procedure) does not support parameters X and Y.
So, why is ODS thinking it should be using any querystring values at all when I have explicitly set the entityID parameter (of type Asp:Parameter)? How do I stop this from happening?
The Html:
[Code]....
The OnSelecting:
[Code]....
I see this odsList_OnSelecting being hit and the inspection of e.InputParameters only contains my expected single entry.
View 4 Replies
Apr 19, 2010
I'm passing on two Querystrings "ddl2" and "ddl3" onto an aspx page. At this page I'm running a SQL Query which has a WHERE clause in it that SHOULD use both the querystrings but only one of the two QS works at a time. When I use only "ddl2" OR only "dd3" in the WHERE clause the result is shown but not when both the Querystrings are used.
Below is the link to the page i get where I use the two QS's.
~/Option1_result.aspx?ddl2=722&%20ddl3=CA
Below is my SQL code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Inventory_DBConnectionString3 %>"
SelectCommand="SELECT * FROM [CA] WHERE (([LATA] = @LATA) AND ([State] = @State))">
<SelectParameters>
<asp:QueryStringParameter Name="LATA" QueryStringField="ddl2" Type="Int16" />
<asp:QueryStringParameter Name="State" QueryStringField="ddl3" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
View 2 Replies
Mar 5, 2011
I have a small problem with a querystring that populates 4 dropdowns.
On page A I have a hyperlink that adds 4 values to my url and on page B I have 4 dropdowns. I am able to click the link and the dropdowns are populated with the correct data! My problem is I do not know how to fire the postback event from DDL4 that shows my data!
[Code]....
My Sql statement:
[Code]....
As you can see from my code there are 2 control parameters. When DDLPrice is selected my page shows all the data. But when I use the querystring method it does not.
I load the querystring from my page load event
[Code]....
View 2 Replies
Jun 29, 2010
this has to be a simple thing but I am missing it
here's what i have
the null condition and query works
the not null condition does not
I have tried:
ImageID=@id error myust declare @id
ImageID=id invalid column id
ImageID=?id incorrect syntax at ?
all errors occur at SqlDataReader Dr = Cmd.ExecuteReader();
int id = Convert.ToInt32(Request.QueryString["id"]);
string SQLquery ="";
if (id == null)
{
SQLquery = "Select Top 1 ImageData,ImageType from WebBGImages ORDER BY NEWID()";
}
else
{
SQLquery = "Select ImageData,ImageType from WebBGImages where ImageID=@id";
}
SqlCommand Cmd = new SqlCommand(SQLquery, connection);
SqlDataReader Dr = Cmd.ExecuteReader();
View 1 Replies
Jun 8, 2010
I have a simple page that will display data from a particular category, using a querystring to filter my data in my sql select statement.
However, I would like to show all my data if there is no querystring present. Is there a simple way to do this?
View 6 Replies
Aug 7, 2010
I need to get a querystring in a select parameter
datasource.selectparameters.add("PostId", request.querystring("PostId"))
Something like that...but...i cant get the snytax right.
View 3 Replies
Feb 7, 2010
.cs code is
[Code]....
and .aspx code is
[Code]....
now i want to pass value in Reply.aspx?C={0} to stored procedure
View 3 Replies
Jan 7, 2011
I have a question related to <asp:SqlDataSource's SelectCommand. How to pass a querystring like <%# Eval("PhotoID") %> in the selectCommand. The whole frontend code is attached. I put
<%# Eval("PhotoID") %> and the photoid gets printed in the page.
<%# Eval("PhotoID") %> is the current displayed picture's PhotoID.
I want to pass this PhotoID or I want to pass <%# Eval("PhotoID") %> to the select command dynamically. I have tried the following approaches:
1) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = @pID"> <SelectParameters><asp:Parameter Name="pID" DefaultValue="7" /></SelectParameters> </asp:SqlDataSource> The above works but it gives only information about PhotoID 7, but there are other photos; How to set pID's value to <%# Eval("PhotoID") %> in ASP .NET's frontend page? then I also tried,
2) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = <%#'Eval("PhotoID') %>"></asp:SqlDataSource> Gives Parser error: Parser Error Message: The server tag is not well formed.
What I should do so that I can pass current PhotoID to SelectCommand? The frontend code:
<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Your Name Here | Picture Details"
CodeFile="Details.aspx.vb" Inherits="Details_aspx" %>
<asp:content id="Content1" contentplaceholderid="Main" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="shim solid"></div>
<div class="page" id="details">
<%--Update Panel Here--%>
<asp:UpdatePanel runat="server" ID="updatepanel">
<ContentTemplate>
<asp:formview id="FormView1" runat="server" datasourceid="ObjectDataSource1" cssclass="view"
borderstyle="none" borderwidth="0" CellPadding="0" cellspacing="0" EnableViewState="false" AllowPaging="true">
<itemtemplate>
<div class="buttonbar buttonbar-top">
<a href="Albums.aspx"><asp:image ID="Image1" runat="Server" skinid="gallery" /></a>
<asp:ImageButton ID="ImageButton9" Runat="server" CommandName="Page" CommandArgument="First" skinid="first"/>
<asp:ImageButton ID="ImageButton10" Runat="server" CommandName="Page" CommandArgument="Prev" skinid="prev"/>
<asp:ImageButton ID="ImageButton11" Runat="server" CommandName="Page" CommandArgument="Next" skinid="next"/>.................
View 14 Replies
Jan 21, 2010
after I pass querystring parameter to page,page works as expected,but after that when I change my control parameter(dropdownlist selected value how can I set querystring to null or empty...
View 1 Replies
Feb 8, 2010
I found this function on [URL] It works great and I can get the properties and display them in separate binds. This is how I call the function, as shown In the link above
SELECT userid, username,
dbo.aspnet_Profile_GetProfile(userid, 'FirstName', DEFAULT) AS FirstName,
dbo.aspnet_Profile_GetProfile(userid, 'LastName', DEFAULT) AS LastName
FROM aspnet_users
However, i cant get it to work with a simple querystring...
<SelectParameters>
<asp:QueryStringParameter Name="username" QueryStringField="user" Type="String" />
</SelectParameters>
I want to fetch a users First and last name with a querystring, for example (default.aspx?user=DemoUser) But it doesn't work, it displays the latest entry in the aspnet_profile table. Btw, im trying to display it in a formview.
View 3 Replies