what type of datatype i use for storing Articles?

Posted by Bageshkumarbagi under Sql Server on 10/31/2012 | Points: 10 | Views : 2159 | Status : [Member] | Replies : 7
hi
I am developing an Article Forum. where i find the problem to storing the article content.
I use varchar(MAX) datatype but it is showing problem when content is more than 500 word .
it will so error and it will not store my database.
plz tell me which datatype use for storing the artical content.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Sourabh07 on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
hi..

try to use "text" datatype for this forum...

it might solve your problem.

Sourabh07

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
Set the datatype of content column of article as "Text" or "ntext".
ntext
Variable-length Unicode data with a maximum string length of 2^30 - 1 (1,073,741,823) bytes. Storage size, in bytes, is two times the string length that is entered. The ISO synonym for ntext is national text.
text
Variable-length non-Unicode data in the code page of the server and with a maximum string length of 2^31-1 (2,147,483,647). When the server code page uses double-byte characters, the storage is still 2,147,483,647 bytes. Depending on the character string, the storage size may be less than 2,147,483,647 bytes.

Note: Microsoft has announced that these datatypes might be removed in the future versions of Sql Server. If it a long term application better not to use them. If it works perfect use nvarchar(MAX) otherwise use text/ntext.

Regards,

Awesome Coding !! :)

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
Sorabh and vasanth thanks for giving answer .
but i am facing same problem .when i store the content of textbox in database it will not store . it show error like
Incorrect syntax near 's'. Unknown object type 'a' used in a CREATE, DROP, or ALTER statement. Unclosed quotation mark after the character string ')'.

plz help me.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
Can you post your code or query.

Awesome Coding !! :)

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
hi Bageshkumarbagi,..

will you please add the code where it shows an error....

also, thanks Vasanthmvp for introducing new datatype ntext in my dictionary.........Because, till now i am not familar with it.


Sourabh07

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
hi
this is sourse code
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="Artical Title"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Artical number"></asp:Label><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>



</div>
<p> <asp:Label ID="Label3" runat="server" Text="Artical"></asp:Label></p>
<p>
<asp:TextBox ID="TextBox2" runat="server" Height="168px" TextMode="MultiLine"
Width="556px"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</p>
</form>
</body>
</html>

==============Cs code=====================
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection("Data Source=SYNCGDC0467;Initial Catalog=naga;Integrated Security=True");
con.Open();
string sql = "insert into articles (id,tatle,article)values("+TextBox3 .Text +",'"+TextBox1.Text +"','"+TextBox2.Text+"')";
SqlCommand cmd = new SqlCommand(sql,con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("Data inserted sucessfully");
}
catch (Exception ea)
{
Response.Write(ea.Message);
}

}

==============datadase design===========
id int
title varchar(500)
article ntext
===============================

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
string sql = "INSERT INTO ARTICLES ([ID],[TITLE],[ARTICLE]) VALUES ("+ int.parse(TextBox3 .Text) + ",' " + TextBox1.Text + " ',' " + TextBox2.Text + " ')"; 

The query is correct, there might be a small mistake some where.
Its not a good approach to include direct textbox values. Always use sql parameters in the query and assign text box values to them.
Try this:
object obj = cmd.ExecuteNonQuery();
If obj is not null then record inserted success.

Awesome Coding !! :)

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response