i code to row has content and i have to split it into sentence using button in gridview and store into table so i have written this code.but its not working
x.aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="219px" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand1">
<Columns>
<asp:BoundField DataField="ContentText" HeaderText="ContentText" SortExpression="ContentText" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btn1" Text="Split into Sentences" runat="server" CommandName="click" CommandArgument="<%# Container.DisplayIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Jobe101ConnectionString %>" SelectCommand="SELECT [ContentText] FROM [Contents]"></asp:SqlDataSource>
x.aspx.cs
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e )
{
if (e.CommandName == "click")
{
int index = Convert.ToInt32(e.CommandArgument.ToString());
GridViewRow row = GridView1.Rows[index];
var text = GridView1.Rows[index].Cells[0].Text;
String[] sentences = Regex.Split(text, @"(?<=[.!?])\s+(?=\p{Lt})");
System.Data.DataTable dt1 = new System.Data.DataTable();
dt1.Columns.Add("SentenceText");
foreach (string value in sentences)
{
dt1.Rows.Add(value);
}
string sql = "";
string apply = "";
for (int i = 0; i < dt1.Rows.Count; i++)
{
sql = sql + "insert into Sentences(SentenceText) select '" + dt1.Rows[i]["SentenceText"].ToString() + "' where not exists(select SentenceText from Sentences where='" + dt1.Rows[i]["SentenceText"].ToString() + "')";
apply = apply + "insert into ContentSentences(ContentID)select ContentID from Contents";
}
}
what is problem???/