Last post Jun 23, 2011 02:36 PM by stevenfe
Jun 22, 2011 09:31 AM|stevenfe|LINK
I do have the following code to execute an insert:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="INSERT INTO [PLS_ARCH] ([Checked], [Userid], [Done], [Entity], [Environment], [TO_DO], [Description], [HOW_TO], [link_to_proc], [overtime], [processing_date], [driver]) (select Checked,Userid,DONE,Entity,Environment,TO_DO,Description,HOW_TO,LINK_TO_PROC,overtime,processing_date,driver from PLS_DAILY where entity=@entity and environment=@environment)" >
<asp:Parameter Name="Entity" Type="String" />
<asp:Parameter Name="Environment" Type="String" />
linked with the following VB.NET code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If DropDownList1.SelectedValue = "EB" And DropDownList2.SelectedValue = "PROD" Then
SqlDataSource2.InsertParameters("entity").DefaultValue = DropDownList1.SelectedValue
SqlDataSource2.InsertParameters("Environment").DefaultValue = DropDownList2.SelectedValue
From a table point of view I did put the fact that column 'userid' can not contain NULL values. As such when the insert is execute and when one row has anyway the NULL value the following erromessage is returned in your webbrowser:
Cannot insert the value NULL into column 'Userid', table 'H:\PLS\APP_DATA\PLS.MDF.dbo.PLS_ARCH'; column does not allow nulls. INSERT fails.
I want to catch this error and give a proper text to the end-user => 'please make sure your userid is filled in'.
I was trying to do this via the SQLdatasource inserting event but no clue ... .
Can somebody help me.
Jun 22, 2011 10:30 AM|AZMatt|LINK
I would use a try/catch.
Jun 23, 2011 02:36 PM|stevenfe|LINK
many tanks ! I didn't know the try/catch 'feature' (still leaning a lot in ASP.NET
Tried today and did succeed.