SQLDataSource - Using The Latest Index From An Insert Elsewhere On A Page
May 22, 2006
I have a page that has a drop down control that is used to control the items in a FormView. The drop down is bound to one SQLDatasource while the FormView is bound to another SQLDataSource. I've got everything working great. Selecting an item in the drop down reveals the details in the form view. the Form can be opened for editing and deleting. I even have the Insert working. But there lies my problem. Once the Insert is executed I'd like to take the Index value of the recently submitted item and set it to the SelectedIndex of my dropdown. Here is the code for each of the SQL events Sub FormViewUpdated(ByVal sender As Object, ByVal e As FormViewUpdatedEventArgs) Handles FormView1.ItemUpdated
confirmation.Visible = True
confirmation.Text = "<img src=""../img/smiley36.gif""> Your record has been updated."
Dim index As Integer = Me.DropDownList1.SelectedIndex
DropDownList1.DataBind()
Me.DropDownList1.SelectedIndex = index
End Sub
Sub FormViewDeleted(ByVal sender As Object, ByVal e As FormViewDeletedEventArgs) Handles FormView1.ItemDeleted
confirmation.Visible = True
confirmation.Text = "<img src=""../img/smiley36.gif""> Your record has been deleted."
DropDownList1.DataBind()
FormView1.ChangeMode(FormViewMode.ReadOnly)
End Sub
Sub FormViewInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs) Handles FormView1.ItemInserted
confirmation.Visible = True
confirmation.Text = "<img src=""../img/smiley36.gif""> Your record has been inserted."
DropDownList1.DataBind()
End Sub
I would like to do something similar to the Updated event in the Inserted sub. Notice I have a Me.DropDownList.SelectedIndex bit...I'd like to be able to set a variable to the new ID and then set the Me.DropDownList.SelectedIndex to that variable. My stored proc for the Insert reads like
ALTER PROCEDURE dbo.usp_INSERTHelp_Faq
(
@FAQQuestion varchar(500),
@FAQText ntext,
@FAQIndex varchar(500),
@ModifiedBy int,
@Help_FAQID int OUTPUT
)
AS
INSERT INTO Help_FAQ (FAQQuestion, FAQText, FAQIndex,ModifiedBy, Views)
VALUES (@FAQQuestion,@FAQText,@FAQIndex,@ModifiedBy,0)
SELECT @Help_FaqID = @@Identity
RETURN
So, the Stored Proc is set up to return the latest ID. Also, my SQLDataSource for the FormView has an InsertParameter: <asp:Parameter Direction="Output" Name="Help_FAQID" Type="Int32" />
Any thoughts on how to close the loop here? How do I get my hands on the new Help_FAQID?
View 3 Replies
ADVERTISEMENT
Sep 11, 2006
Hello, I'm new to the forum and new to SQL, ASP.NET, etc. I am creating an intranet site for my company in VS 2005 and have run into a very annoying problem that I can't seem to solve. I have tried Googling it and came up empty. I have a database in SQL Express 2005 and my website will be accessing several tables within the database. I can retrieve info just fine and I can update, delete, etc just fine using gridview or other prebuilt tools, but when I add a few text boxes and wire a button to the SqlDataSource.Insert() command, I get a new record that is full of null values except for the identity key I have set. The kicker is that I am also using a master page and when I duplicate the web page without the master page link, everything works just fine. The following snippets show what I'm doing:<InsertParameters><asp:FormParameter Name="Name" Type="String" FormField="txtName" /><asp:FormParameter Name="Location" Type="String" FormField="ddlLocation" /><asp:FormParameter Name="Issue" Type="String" FormField="txtProblem" /></InsertParameters>Of course I match the formfields to the text boxes, create an onclick event for my button, the sqldatasource is configured correctly, it just doesn't work with the master page no matter what I do. Any help would be appreciated. Thanks
View 3 Replies
View Related
Jan 25, 2008
Hi!
using table partition;
is it possible to build index only on the latest partition?
Best regards
View 4 Replies
View Related
Jul 23, 2007
What is the C# code I use to do this?
I'm guessing it should be fairly simple, as there is only one row selected. I just need to pull out a specific field from that row and then insert that value into a different SqlDataSource.
View 7 Replies
View Related
Oct 10, 2005
Hi all,I have 2 tables: Applicant_Table, Applicant_Resume_Table
In my web application, after applicant click "submit" for his job application, the information will be saved to Applicant_table in SQL Server. But in a SQL statement, how to get his Applicant_ID, so that I can save his resume to another table on his Applicant_ID?Thank you.
View 2 Replies
View Related
Nov 19, 2006
Hi,
I have the following Sql Data Source that I wish to bring back on my page:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:FrogConnectionString %>"
SelectCommand="ProposalsCheckNewCustomerData" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:FormParameter FormField="MaritalStatusID" Name="MartialStatusID" Type="Int32" />
<asp:FormParameter FormField="LivingStatusID" Name="LivingStatusID" Type="Int32" />
<asp:FormParameter FormField="DealerID" Name="DealerID" Type="Int32" />
<asp:FormParameter FormField="VehicleTypeID" Name="VehicleTypeID" Type="Int32" />
<asp:FormParameter FormField="FinanceTypeID" Name="FinanceTypeID" Type="Int32" />
<asp:FormParameter FormField="MediaSourceID" Name="MediaSourceID" Type="Int32" />
<asp:FormParameter FormField="DealerContactID" Name="DealerContactID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
The recordset brings back 7 values that I wish to populate into 7 Labels.
1. Should the SqlDataSource be on the page (between the Head tags) or within the Page_Load command of the Page Behind ?- If its on the page behind do any of you have any sample code to show me how to get the recordset up and running ?
2. How would I bind the results to a label ?- Within my old asp pages it was simple (I'm not saying its not simple here, I am still getting my head around vb.net)- eg <%=rsX("MaritalStatus")%> I guess its something very similar
Thanks for any pointersFizzystutter
View 4 Replies
View Related
Nov 26, 2006
Hi,
I placed several SqlDataSource objects on my page which work with the same database (same connection string).
As I know, connection operation to database is costly in the performance prespective.
Do these SqlDataSource controls work with the same connection object or each of them create his own connecton object?
If each create it's own, then can they be changed to work with one connection object?
Thanks
View 3 Replies
View Related
Aug 29, 2006
I use SQLDataSource, bind to a GridView and a SelectParameter that gets it's value from a textbox. If the textbox is empty, then it returns all rows.How do I prevent the query and binding when the page first load? Thanks
View 11 Replies
View Related
Jun 8, 2007
Thanks for your help.
I'm just getting into ASP.NET 2.0 and started using the SqlDataSource control to declaritively connect to a database. I was wondering if I have two SqlDataSource controls on one page with two select commands querying the same database, will the that create to seperate instances of opening and closing the connection to the database, or will it open the database once, execute both queries, and then close the connection. It seems that if it creates two separate connections, it would still be more efficient to to connect to the database programmatically using ADO.NET. You would only need to make one trip to the database, pull down all of your data, and then close the connection.
Adrian
View 1 Replies
View Related
Feb 1, 2007
i have a sqldatasource on my asp.net page -- select * from table where id = @id
i want to set the @id in the backend and set the result to textbox1.text
how do i do this?
View 1 Replies
View Related
Feb 17, 2006
1. Create a new .aspx page and add this inside the form tag: <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Comments]" InsertCommand="INSERT INTO Comments(CommentAuthor, CommentText) VALUES (@auth, @text)"> <InsertParameters> <asp:FormParameter FormField="TextBox1" Name="auth" /> <asp:FormParameter FormField="TextBox2" Name="text" /> </InsertParameters> </asp:SqlDataSource> </div>2. Add the event handler for the button in code behind: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Me.SqlDataSource1.Insert() End Sub3. Run the page, enter some text into the textboxes and hit the button. GREAT! The data was successfully inserted into the database.Now, let's try the exact same thing, but this time lets create a Master Page first. So:1. Create a new master page.2. Create a new .aspx page, check the 'select master page' checkbox and then select the newly created master page.3. Add the exact same as above in between the asp:Content begin and end tags: <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Comments]" InsertCommand="INSERT INTO Comments(CommentAuthor, CommentText) VALUES (@auth, @text)"> <InsertParameters> <asp:FormParameter FormField="TextBox1" Name="auth" /> <asp:FormParameter FormField="TextBox2" Name="text" /> </InsertParameters> </asp:SqlDataSource> </div>4. Add the event handler for the button in code behind. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Me.SqlDataSource1.Insert() End Sub5. Run the page, enter some text into the textboxes and hit the button. WHOOT!? This time it doesn't work and the following error appears:Cannot insert the value NULL into column 'CommentAuthor', table 'C:DOCUMENTS AND SETTINGSSONYMY DOCUMENTSVISUAL STUDIO 2005WEBSITESCOMMENTSAPP_DATACOMMENTS_DB.MDF.dbo.Comments'; column does not allow nulls. INSERT fails.The statement has been terminated. 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: Cannot insert the value NULL into column 'CommentAuthor', table 'C:DOCUMENTS AND SETTINGSSONYMY DOCUMENTSVISUAL STUDIO 2005WEBSITESCOMMENTSAPP_DATACOMMENTS_DB.MDF.dbo.Comments'; column does not allow nulls. INSERT fails.The statement has been terminated.Source Error: Line 4: Line 5: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.ClickLine 6: Me.SqlDataSource1.Insert()Line 7: End SubLine 8: End Class Source File: C:Documents and SettingsSONYMy DocumentsVisual Studio 2005WebSitesComments2.aspx.vb Line: 6 So can anyone explain why this only works in the first example?Many thanks,
View 4 Replies
View Related
Feb 22, 2008
Using 3.5
If I have a sqldatasource on the page, is it run if it is not bound to a data object like a gridview?
Seems like if i want to access the data (like set a label text) from the sqldatasource I have to use code to first create a dataview then pick throught it. This seems like I'm running it twice. I'm new at .net so I dont know how to tell.
I don't want to write data select code programatically when I can just through an SDS on the page, but wondered it it ran just because it's on the page.
View 2 Replies
View Related
Mar 1, 2007
Can I roll back certain query(insert/update) execution in one page if query (insert/update) in other page execution fails in asp.net.( I am using sqlserver 2000 as back end)
scenario
In a webpage1, I have insert query into master table and Page2 I have insert query to store data in sub table.
I need to rollback the insert command execution for sub table ,if insert command to master table in web page1 is failed. (Query in webpage2 executes first, then only the query in webpage1) Can I use System. Transaction to solve this? Thanks in advance
View 2 Replies
View Related
Jan 22, 2008
Hi
I have a table called "Jobs" on my SQL server. I have an access front end which connects to this as well as some access backend tables.
We have 30+ users on the system. There are 1000s of records in this "jobs" table.
For some reason, at certain points of the day all users are stopped from updating a group of records. No-one can update values in a clump of records. It is usually 10-20 records that are numerically together.
When i kick everyone off the system, and log back those particular records seem to be unlocked.
I can rule out permissions on the Jobs table. i am failry certain they have been set correctly.
To me it sounds like Page locking. Now i am new to SQL server. I am inheriting a recently created sql system.
But i notice there are multiple indexes formed on this JOBS table. I looked at one in particular. It is a "ClientName" field.. I noticed under this index > options...it says "Use Page locks when accessing the index".
Am i interpreting this right... But anyone searching under this field, will page lock on that table.
And...if my memory serves me right, "page locking" locks a group of all the nearest records?
Is this correct?
Does this sound like where my system is going wrong?
Thanks
Conor
View 2 Replies
View Related
Mar 5, 2007
Hi
Using ASP.NET 2.0, Sql Server 2005.
I have a simple page (NOT a formview) with some entries textbox's , checkbox and dropdownlistbox's
I want to link a datasource to the 'Item Page' and bind the datasource's values to the page
The select statement is
Select a.IssueID,
a.ProjectID,
a.VersionID,
a.toincludeversionid,
a.Version,
a.toincludeversion,
a.TypeofEntryID,
a.PriorityID,
a.WorkFlowID,
a.Title,
a.Area,
a.Details,
a.Question,
a.Answer,
a.HowToRepro,
a.DevelopersNotes,
a.TestersNotes,
b.ProjectID,
b.ProjectName,
OldVersion.Version,
ToIncludeVersion.Version,
d.DESCRIPTION,
e.DESCRIPTION,
x.TaskID as TaskID,
x.DESCRIPTION as TaskDescription,
z.Taskdone,
CONVERT (char(9),z.TaskAssignedDate, 3) AS Workflowdate,
z.StaffID as StaffID,
w.username,
y.latest_workflowid
from issue as a
Inner join ProjS b on b.ProjectId=a.ProjectID
Left Outer join Version OldVersion on a.VersionID=OldVersion.VersionID
Left Outer join Version ToIncludeVersion on a.VersionID= ToIncludeVersion.VersionID
Inner join TypeOfEntry d on d.TypeOfEntryID=a.TypeofEntryID
Inner join Priority e on e.PriorityID=a.PriorityID
inner join workflow z on z.issueid=a.issueid
Inner join (select issueid,max(workflowid) as latest_workflowid from workflow group by issueid) y on y.latest_workflowid=z.workflowid
Inner join task x on x.taskid=z.taskid
Inner join staffls w on w.StaffID=z.StaffID
Where a.IssueID= @IssueID
I hope I have made query clear, if not I don't mind explaining more.
Thanks in advance
View 1 Replies
View Related
Nov 25, 2005
Hi, I have created a search page which needs to perform different
search function in same page. I have setuped a sqldatasource then
manual
setup the connection string and command inside the codefile. So the
select command can be various depends on the event. The problem is
all of those setting will be reset after I click on the pageindex in
the girdview control to go to next pages. Since this gridview is linked
with this sqldatasource control, I need to restore the connection
string/command when user choose decide to view next page of data inisde
the
gridview.
I think I must have done something wrong in here becuase it will end up
retrieving the total amount of data when everytime user choose to
view next
or perivous page.
Can someone give me a hand on this ? Thanks
View 1 Replies
View Related
Apr 17, 2005
I know the shortcut to 'defragging' the database to eliminate and
reclaim 'whitespace' in data and index pages is to setup a maintenance
plan. This doesn't work for me for two reasons:
1. I like to know how things work.
2. I can not create maintenance plans with my hosted provider.
I use the following T-SQL to rebuild all indexes on all tables:
-- exec sp_MSforeachtable "DBCC DBREINDEX ('?', ' ', 90)
But, does that not only address indexes? What about getting whitepace
back from data in tables themselves?
Am I over-thinking this?
When you're paying for SQL by the MB and generate a lot of data (with a
fair amount of churn) you want to keep it optimized and efficient,
right?
View 1 Replies
View Related
Jul 23, 2005
I've just found a blocking lock occuring in a SQL Server.[color=blue]>From the waitresource, I found that the blocker has the following[/color]information:wait_info: PAGEIOLATCH_EXwait_resource: 14:1:564312And the blockee has the following information:wait_info: LCK_M_Swait_resource: KEY: 14:405576483:2 (7501a5aa8355)The problem is that I do not know which object is the blocker holding,for I understand that for a PAGE lock, it is in the format ofdatabase_id:file_id:page_idI know the db_id, the file_id but don't know how to map the page_id(564312) to a table/index in the database.Can somebody shed some lights on this? thks a lot.
View 4 Replies
View Related
Jul 20, 2005
Hello,I not exactly sure how to determine the table when given the followinginformation:--Could not find the index for RID '999999' in index page('1:99999999'), index id ), database (whatever).--Can you someone tell how I use the system tables to determine whattable this index corresponds to? I'm assuming I used sysindexes andsysobjects somehow.Thanks in advance,JGB_DBA
View 1 Replies
View Related
Dec 3, 2007
I am attempting to understand the behaviour of a nonclustered index in regards to page splitting.
If I had the following table:-
Col1, Col2, Value
This table has a Clustered index on Col1, Col2 and a NonClustered index on Col2 and include Col1, Values.
If inserts into Col1 were causing page splits in the Clustered index, what are the effects on the NonClustered index?
I am attempting to understand what happens to the NonClustered index in this scenario so that I can make a decision on what fillfactor to use.
View 5 Replies
View Related
Jan 25, 2008
Table A
5.6GB
80 million rows
Initial Page Space Used = 85.7% (sys.dm_db_index_physical_stats - avg_page_space_used_in_percent)
Index and data size are almost unchanged after an ONLINE rebuild of the clustered index. Page count actually goes up by 800. No fill factor or pad index settings. Page space used = 99.2%
During an OFFLINE rebuild the page count drops by ~20%. Page space used = 99.8%.
How can the pages be 99.2% used yet the number of pages hasn't gone done from the ONLINE rebuild?
I'm getting the feeling a shortcut was taken somewhere. Does an ONLINE rebuild only reorganize leaf level index pages but not any of the upper levels? Essentially it puts the pages in order but doesn't do any structure consolidation like OFFLINE?
It would seem that you're missing out on some of the benefits of defragmenting if your data is still spread across more pages and you don't get as many rows per read or it takes more reads to go down your tree to get to your data.
View 8 Replies
View Related
Apr 9, 2015
i have one col in a nonclusted index which is bigint 8 bytes follwoing result shows min_record_size_in_bytes and max_record_size_in_bytes is 20 that is 12+8 page size is 8 kB. does that mean a record will use 20 bytes in a page or it will only use the space equalent to data stored in the col.what i have seen is page count is same weather i put some data in the col or null
select * From sys.dm_db_index_physical_stats(9,343,null,null,'DETAILED')
database_idobject_idindex_idpartition_numberindex_type_descalloc_unit_type_descindex_depthindex_
levelavg_fragmentation_in_percentfragment_countavg_fragment_size_in_pagespage_countavg_page_
space_used_in_percentrecord_countghost_record_countversion_ghost_record_countmin_
record_size_in_bytesmax_record_size_in_bytesavg_record_size_in_bytesforwarded_
record_countcompressed_page_count
999208304101HEAPIN_ROW_DATA102.9527559055118116253.187540514.196627131208358500016516516500
9992083041141NONCLUSTERED INDEXIN_ROW_DATA202553.21699.3544600938967585000202020NULL0
9992083041141NONCLUSTERED INDEXIN_ROW_DATA2101115.510254509513221600262626NULL0
View 1 Replies
View Related
Jul 16, 2015
We noticed a deadlock 3-4 weeks ago on a table (table1) and deadlock graph was captured.
When I am analyzing the deadlock graph, page number using DBCC PAGE, I am getting the object id for a different table (table2). But deadlock graph shows the name of the object as table1.
Is it possible that subsequent defragmentation of indexes would have caused the respective page id to got re-allocated to a different table? I checked the deadlock graph lately only after 3-4 weeks.
View 1 Replies
View Related
Nov 13, 2007
Hi,I am trying to insert data using data from a datalist on the page. To do this, I use the following coding: command.CommandText = "INSERT INTO Messages (sendername,recievername,message,Date,subject) VALUES (@sendername,@recievername,@message,@date,@subject)"; command.Parameters.AddWithValue("@sendername", System.Web.HttpContext.Current.User.Identity.Name); command.Parameters.AddWithValue("@recievername", SqlDataSource2 ); command.Parameters.AddWithValue("@message", TextBox2.Text); command.Parameters.AddWithValue("@subject", TextBox3.Text); command.Parameters.AddWithValue("@date", DateTime.Now.ToString()); command.ExecuteNonQuery(); SqlDataSource is the datasource for the other datalist- will this work?Thanks,Jon
View 11 Replies
View Related
Mar 27, 2008
how can I insert a record using variables?
So that
var1="Name1"
SqlDatasource1.Insert(var1)
View 5 Replies
View Related
Apr 24, 2008
Hi. I'm testing GridView and SqlDataSource controls and I'm using this http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insert.aspxI have problems with inserting new items into the db. As I understood from the code in that example, I need to create InsertParamaters and name it just like the one in the insert query. <asp:SqlDataSource ID="Sql1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Clients]" DeleteCommand="DELETE FROM [Clients] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Clients] ([Name]) VALUES (@Name)" UpdateCommand="UPDATE [Clients] SET [Name] = @Name WHERE [ID] = @ID"> <DeleteParameters> <asp:Parameter Name="ID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:ControlParameter Name="Name" ControlID="newClientTB" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="Name" Type="String" /> <asp:Parameter Name="ID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Name" Type="String" /> </InsertParameters> </asp:SqlDataSource> and I get the following error when run:The variable name '@Name' has already been declared. Variable names must be unique within a query batch or stored procedure. Any help?
View 2 Replies
View Related
Jun 30, 2006
Coming from an asp world, I am totally lost on this one.
I have two tables.
tblUsers and tblUserInfo
I have a gridview that gives me the list of users and when selected, it gives me the detailsview of the the record. However, When I need to add a new user, I am trying to add that user into tblUsers (which happens with no problems), and then add a record, using the same user number (UserID) has the key or ID for the tblUserInfo.
So basicly, when I create a new user in tblUsers I want to create a record in tblUserInfo with the same userid.
In ASP, this takes me minutes... I have been trying to figure this out for weeks.
vs2005, sql express.
Thanks.
View 1 Replies
View Related
Jan 4, 2007
Hello there,
I made a page to add these fields (name, description, price, end_date) into a SQL database. I'm using ASP.NET 2.0 with C#, my database is SQL 2005.
I did it without DetailsView or FormView, it consists of TextBoxes and a Calendar. Anyways, i wrote this code for Button1, which is the button that adds the data.
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource sql = LoginView1.FindControl("SqlDataSource1") as SqlDataSource;
sql.Insert();
Response.Redirect("home.aspx");
}
The parameters and insert statments and commands are written from the SqlDataSource Insert Query wizard. But I keep getting this error when trying to click Button1.
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 31: {
Line 32: SqlDataSource sql = LoginView1.FindControl("SqlDataSource1") as SqlDataSource;
Line 33: sql.Insert();
Line 34: Response.Redirect("home.aspx");
Line 35: }
Source File: c:Documents and SettingsDoublethink..!!My DocumentsVisual Studio 2005WebSitesSunnDarkProjectsell.aspx.cs Line: 33
Any ideas how to fix this?
View 4 Replies
View Related
Feb 6, 2007
Hi, I have some problem with inserting data into two separate table which are connected via foreign key like in this example:Students (id_s, name, id_subject)Subjects (id_subject, name)So the point is to add a new student and subject for that chosen student. You have to make two inserts right? but how to pass the primary key to the table with foreign key? The form consists of three texbox: name, name_of_subject. Both id_s and id_subject are increment automatically. Any idea how to do it? I would be very grateful for the working code.Thanks in advance and best regards,N.
View 5 Replies
View Related
Apr 24, 2007
Hey forum,
the .NET form controls make it extremely easy to manage database data, control + SQLdatasource et voilĂ , its there.
i have a web form, and a SQLdatasource with an insert query with parameters (works perfectly, only the Date picker Lite textbox ID as parameter wont register, but i have a thread runnin on their forums for that). when i open the Query builder and execute the query it works! woot! but now, how can i make it execute on a button press? i tried with several commands, like SQLdatasource1.execute, and several other commands i searched (can post later, not behind my test environment with my tools/webpage at the moment). so what is the command to let the SQLdatasource execute it's query? it's all i need to know to make several forms, please ghelp me! :)
gr. michael
View 2 Replies
View Related
Oct 8, 2007
Hi all,
I have few insertions statements in one datasource insert command, which i use for my user creation process adding new billing info shipping info and so on.
I've put this code in createuserwizard usercreated step with a try catch code. On the insertion if it doesnt work it deletes the user account.
Well lets say the first insertion went trough with out any problems, but the second one got blocked or didnt work length or any wierd on controled issue.
I was thinking of putting begin transaction end transaction statements in front and end of the statements but this can prevent the insert not to return error, which will prevent try catch to fire?
Basicly the idea is to do all insertions with the user creation, and if one goes down all the others gets reversed. (if possible single sqldatasource, just to make the code look clean)
View 2 Replies
View Related
Oct 12, 2007
Hello all,
I am having problem to insert the record into database from sqldatasource control. my code is listed below, and i can't find anything why it cause the exception...
<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:WebsiteDataConnection %>" SelectCommand="SELECT * FROM [ServiceAgents]" InsertCommand="INSERT INTO ServiceAgents VALUES(@Ser_STATE, @Ser_CITY, @Ser_AGENT, @Ser_PHONE, @Ser_EQUIPMENT)"> <InsertParameters> <asp:FormParameter Name="Ser_STATE" FormField="TextBox_state"/> <asp:FormParameter Name="Ser_CITY" FormField="TextBox_city"/> <asp:FormParameter Name="Ser_AGENT" FormField="TextBox_agent"/> <asp:FormParameter Name="Ser_PHONE" FormField="TextBox_phone"/> <asp:FormParameter Name="Ser_EQUIPMENT" FormField="TextBox_equip" /> </InsertParameters> </asp:SqlDataSource>
The table has got the fields that needed for insert command, for example:
<table> <tr> <td>State:</td> <td> <asp:TextBox ID="TextBox_state" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox_state" Display="Static" ErrorMessage="Please enter a state." /> </td> </tr> <tr> <td>City:</td> <td> <asp:TextBox ID="TextBox_city" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox_city" Display="Static" ErrorMessage="Please enter a city." /> </td> </tr> <tr> <td>Agent:</td> <td> <asp:TextBox ID="TextBox_agent" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox_agent" Display="Static" ErrorMessage="Please enter a agent." /> </td> </tr> <tr> <td>Phone:</td> <td> <asp:TextBox ID="TextBox_phone" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox_phone" Display="Static" ErrorMessage="Please enter a phone No." /> </td> </tr> <tr> <td>Equipment:</td> <td> <asp:TextBox ID="TextBox_equip" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox_equip" Display="Static" ErrorMessage="Please enter a equipment." /> </td> </tr> <tr> <td></td> <td> <asp:Button ID="Button2" runat="server" Text="Add" OnClick="addEntry" BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="1.0em" ForeColor="#284775"/> </td> </tr> </table>
And in the code i just called: SqlDataSource1.Insert(); Then the page gives me the exception like:
Cannot insert the value NULL into column 'STATE', table 'WebsiteData.dbo.ServiceAgents'; column does not allow nulls. INSERT fails. The statement has been terminated.
But i actually input all the required text in the textbox.... Any idea guys?
Thanks
View 2 Replies
View Related
Oct 22, 2007
SqlDataSource UpdateCommand plus Insert
I have a SqlDataSource with an UpdateCommand but besides that i need also an Insert command triggered on the same update command.
That´s because i need to update a record and at the same time include a log of that update in another database.
Thanks
View 3 Replies
View Related