***using select query result in insert query***
***i have this code in .cs Page
.cs page***
String query = "select userid from tblUser where email='" + EmplyrSession + "'";
SqlCommand com = new SqlCommand(query, con);
try
{
con.Open();
int noRows= com.ExecuteNonQuery();
Response.Write(noRows);
}
catch (Exception ex)
{
Response.Write("Sql Error:" + ex.Message);
}
finally
{
con.Close();
}
***Now i want to use the result returned by this query i.e. userid, in .aspx page,
***
String query = "select userid from tblUser where email='" + EmplyrSession + "'";
***i want to use the result returned by this query i.e. userid, in .aspx page, in insert command of sql datasource***
.aspx page code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="advertisementSubmission.aspx.cs" Inherits="advertisementSubmission" %>
<!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>Submit JobDetails</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DetailsView ID="DetailsView1" runat="server" AccessKey="d"
AutoGenerateRows="False" DataKeyNames="advid" DataSourceID="SqlDataSource1"
DefaultMode="Insert" Height="50px" Width="125px" CellPadding="4"
ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:BoundField DataField="advid" HeaderText="advid" InsertVisible="False"
ReadOnly="True" SortExpression="advid" />
<asp:BoundField DataField="advtitle" HeaderText="advtitle"
SortExpression="advtitle" />
<asp:BoundField DataField="startingdate" HeaderText="startingdate"
SortExpression="startingdate" />
<asp:BoundField DataField="endingdate" HeaderText="endingdate"
SortExpression="endingdate" />
<asp:BoundField DataField="mediumofadv" HeaderText="mediumofadv"
SortExpression="mediumofadv" />
<asp:BoundField DataField="refid" HeaderText="refid" SortExpression="refid" />
<asp:BoundField DataField="jbid" HeaderText="jbid" SortExpression="jbid" ReadOnly="True" Visible="false" />
<asp:TemplateField HeaderText="advDetails" SortExpression="advDetails">
<EditItemTemplate>
<asp:TextBox ID="txtboxAdvDetails" runat="server" Text='<%#Bind("advDetails") %>' TextMode="MultiLine"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Waleed_orsfinalConnectionString %>"
DeleteCommand="DELETE FROM [tblJobAdv] WHERE [advid] = @advid"
InsertCommand="INSERT INTO [tblJobAdv] ([advtitle], [startingdate], [endingdate], [mediumofadv], [refid], [jbid], [advDetails]) VALUES (@advtitle, @startingdate, @endingdate, @mediumofadv, @refid, @jbid, @advDetails)"
SelectCommand="SELECT * FROM [tblJobAdv]"
UpdateCommand="UPDATE [tblJobAdv] SET [advtitle] = @advtitle, [startingdate] = @startingdate, [endingdate] = @endingdate, [mediumofadv] = @mediumofadv, [refid] = @refid, [jbid] = @jbid WHERE [advid] = @advid">
<DeleteParameters>
<asp:Parameter Name="advid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="advtitle" Type="String" />
<asp:Parameter DbType="Date" Name="startingdate" />
<asp:Parameter DbType="Date" Name="endingdate" />
<asp:Parameter Name="mediumofadv" Type="String" />
<asp:Parameter Name="refid" Type="Int32" />
<asp:Parameter Name="jbid" Type="Int32" />
<asp:Parameter Name="advid" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="advtitle" Type="String" />
<asp:Parameter DbType="Date" Name="startingdate" />
<asp:Parameter DbType="Date" Name="endingdate" />
<asp:Parameter Name="mediumofadv" Type="String" />
<asp:Parameter Name="refid" Type="Int32" />
<asp:QueryStringParameter Name="jbid" QueryStringField="jbid" Type="Int32" />
<asp:Parameter Name="advDetails" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
*how would i get this ? HELP PLEASE *
HunainHafeez 9 Posting Whiz
JorgeM 958 Problem Solver Team Colleague Featured Poster
HunainHafeez 9 Posting Whiz
HunainHafeez 9 Posting Whiz
JorgeM 958 Problem Solver Team Colleague Featured Poster
HunainHafeez commented: very nice example jorgrm , thanks alot but you didn't get me exactly, what i want to do is that i want the result of query in my .aspx page, as u see that i called executenonquery() method to run select quey and this method only no of rows affected not th +2
JorgeM 958 Problem Solver Team Colleague Featured Poster
HunainHafeez 9 Posting Whiz
JorgeM 958 Problem Solver Team Colleague Featured Poster
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.