I have the following SP:
ALTER proc [CRM].[s_CRM_GetEmail]
(
@EmailTemplateID int
)
AS
BEGIN
SELECT
CASE
WHEN @EmailTemplateID = 1 THEN 'This is EmailTemplate 1'
WHEN @EmailTemplateID = 2 THEN 'This is EmailTemplate 2'
END AS EmailBody
FROM [CRM].[CRMData]
WHERE CRM_ID = 1
END
The following is my webform:
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="Type" runat="server">
<asp:ListItem Value="0" Selected="True">Select Email Template:</asp:ListItem>
<asp:ListItem Value="1">Bike Template</asp:ListItem>
<asp:ListItem Value="2">Car Template</asp:ListItem>
</asp:DropDownList>
</div>
<p><asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="OK" /></p>
</form>
<textarea name="'emailbody" rows="20" cols="100"/> </textarea>
Lastly, the following is my code thus far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = "Data Source=Server1;Initial Catalog=Server_Logistics;Integrated Security=True";
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
String id = Type.SelectedValue;
int emailid = Int32.Parse(id);
using (SqlCommand cmd = new SqlCommand("CRM.s_CRM_GetEmail", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@EmailTemplateID", SqlDbType.Int).Value = emailid;
using(SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
Console.WriteLine(rdr["EmailBody"]);
}
}
}
}
}
}
I want to extract the contents based upon user drop-down box selection. So far I've got it to connect to DB but I'm not sure how to extract the data and display. Ideally I want to extract it in the textarea on the webform, but either way just want to extract data. I would be grateful for any guidance.
I've got it to finally extract! I've replaced Console.WriteLine(rdr["EmailBody"]); with Response.Write((rdr["EmailBody"])); Next question is is there a way to get this populating in the textarea on the webform?