Hi, I recently did the how to page in saving xml to a database. After successfully completing it, I migrated the code over to my own page. I'm trying to make the connection pull the xml from CuteEditor and save it to the database. I would like the ID to be an auto incremental number, as opposed to having to enter it manually.
basically I'm trying to take the xml from the CuteEditor and and save it to a sql database, to be displayed on a news page. each post will be a separate news article.
I believe the following in red is where I need to make some changes, I just don't know how to specify CuteEditor as the source.
Thanks for looking.
int ID = Convert.ToInt32(txtID.Text);
string xmlValue = txtPost.Text;
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Post_News.aspx.cs" Inherits="News_Post_News_Default" Title="Post_News" %>
<%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.Sql" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Data.SqlTypes" %>
<asp:Content ID="Content2" ContentPlaceHolderID="PortalCPH" runat="Server">
<script runat="server">
void btnSave_Click(object sender, EventArgs e)
{
int ID = Convert.ToInt32(txtID.Text);
string xmlValue = txtPost.Text;
//Get the connection string from the web.config file
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["SumbmitNews"].ConnectionString;
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Insert News(ID, Post) Values(@ID, @Post)";
//Set value of parameters
SqlParameter firstColParameter = cmd.Parameters.Add("@ID", SqlDbType.Int);
firstColParameter.Value = ID;
SqlParameter secondColParameter = cmd.Parameters.Add("@Post", SqlDbType.Xml);
secondColParameter.Value = new SqlXml(new XmlTextReader(xmlValue, XmlNodeType.Document, null));
//Execute update and close connection
cmd.ExecuteNonQuery();
}
Response.Write("Saved values successfully");
}
</script>
<div id="Post_News_Head" align="center">
<h1 style="color: #0000FF">
Post a News Article.</h1>
<p style="color: #0000FF; height: 20px;">
Thank You for Contributing,
<asp:LoginName ID="LoginName2" runat="server" />
.</p>
<hr style="color: #9D9F97; height: 5px;" />
<div>
<table align="center" style="width: 100%">
<tr>
<td>
<p align="center">
Catagory:
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
Subcatagory:<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</p>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</div>
<div id="cuteeditor" align="center">
<CE:Editor ID="Editor1" runat="server" Height="226px" />
<asp:Button ID="btnSave" runat="server" Text="Save Values" Width="118px" Height="30px"
OnClick="btnSave_Click" />
</div>
</asp:Content>