Hello,

I am faily new to ASPX programming and needed some help. I have a web page with a button. As a test, I am trying to create a procedure on the button click event that will run an SQL statment to select the Program for which a user belongs based on the environment.username variable. I have already been able to get the environment.username part of it however I am having a hard time figuring out within the button click event, how to run the SQL statement and then reference the label or text box that would contain the result...

I am using VB since im am a little more familiar with VB through working with Access...

Thanks for any help you can provide.

Robby

Recommended Answers

All 2 Replies

you want to write your database code on client side or is it ok to write on server side code?

you want to write your database code on client side or is it ok to write on server side code?

Well basically whatever is best. I do have a code behind file that is running the button event so I am going to say that this is running on the server side... I found a tutorial for a basic data entry form and have modified it somewhat to enable me to add to the table only the fields which are on the form plus a date variable. I am looking for adding other variables so I would like to know how to assign a variable data but not necessarily from a control (perhaps an SQL select statement)...

The other thing I would like to know at this point is how to call the web page (SubmitConfirm.aspx) i created with a green checkmark and text indicating that the record was added successfully. I tried adding it's url to the postbackurl value of my button but that causes the insert command to not be executed. I would like to add code after the insert command within the code behind file to call that page so that I am sure the insert command has a chance to run before showing the confirm page...

so here is the code:
This is my button code:

<td align="center">
                                <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />                               
                                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:BESS_SQLConnectionString %>" 
            InsertCommand="INSERT INTO [tblQandA] ([Program], [Subject], [Question], [Date], [Rwsrc]) VALUES (@Program, @Subject, @Question, GetDate(), @Rwsrc)" 
            SelectCommand="SELECT * FROM [tblQandA]">
                        <InsertParameters>
                <asp:Parameter ConvertEmptyStringToNull="True"  Name="Program" Type="String" />
                <asp:Parameter ConvertEmptyStringToNull="True"  Name="Dept" Type="String" />
                <asp:ControlParameter ControlID="txtSubject" PropertyName="text" Name="Subject" Type="String" />
                <asp:ControlParameter ControlID="txtQuestion" PropertyName="text" Name="Question" Type="String" /> 
                <asp:ControlParameter ControlID="txtAttach" PropertyName="text" Name="Rwsrc" Type="String" />
                
                
            </InsertParameters>
        </asp:SqlDataSource>
                            
                            </td>

This is the calling code in the code behind file:

SqlDataSource1.Insert()

Thanks for your help!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.