Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am new at asp.net and sql server 2008. i have to write store procedure before that i explain you about database.

SQL
Content(contentid ident,contenttext varchar(500))
sentence(sentenceid ident,sentencetext varchar(500))
contentsentence(contentid,sentenceid,order no all are int)


and both content and sentence table has relation of pk and fk with contentsentence table.

i have write code that split content into sentence and data enter into sentence table.so i have to write store procedure that get current generated sentence id which can find using @@identity from sentence table and get contentid from which sentence is generated and also enter orderno which is manual inserted and stored in one variable.so when this store procedure fires its take value of currently generated sentenceid its related content id and manual entered orderno. this feilds inserted in contentsentence table.

i don't know how to write store procedure for this so please help me!!!

protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e )
 { 
 if (e.CommandName == "click")
 {
  
 int index = Convert.ToInt32(e.CommandArgument.ToString());
  
 if(index<0)
 {
 return;
 }
  
 GridViewRow row = GridView1.Rows[index];
  
 var text = GridView1.Rows[index].Cells[0].Text;
  
 string tb = ((TextBox)GridView1.Rows[index].FindControl("txt1")).Text;
  
 String[] sentences = Regex.Split(text, @"(?<=[.!?])\s+(?=\p{Lt})");
  
 System.Data.DataTable dt1 = new System.Data.DataTable();
  
 dt1.Columns.Add("SentenceText1");
  
 foreach (string value in sentences)
 {
 if(!string.IsNullOrWhiteSpace(value))
 dt1.Rows.Add(value);
 }
 SqlConnection con = new SqlConnection(conn);
 con.Open();
 string sql = "";
 for (int i = 0; i < dt1.Rows.Count; i++)
 {
 sql = sql + "INSERT INTO Sentences(SentenceText) SELECT '" + dt1.Rows[i]["SentenceText1"].ToString() + "' FROM Sentences WHERE NOT EXISTS(SELECT '" + dt1.Rows[i]["SentenceText1"].ToString() + "' FROM Sentences WHERE SentenceText='" + dt1.Rows[i]["SentenceText1"].ToString() + "')";
 sql = sql + "";
 SqlCommand cmd = new SqlCommand(sql, con);
 cmd.ExecuteNonQuery();
 }


i have store value of dt1.Rows[i]["SentenceText1"].ToString() in one variable name abc and how can use this variable name abc in store procedure as input parameter to insert that variable's value.
Posted
Updated 4-Mar-15 20:52pm
v4
Comments
coded007 5-Mar-15 2:15am    
Have to tried any thing on this part.. if so please post it we will help you
vatsaldesai 5-Mar-15 2:19am    
protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e )
{
if (e.CommandName == "click")
{

int index = Convert.ToInt32(e.CommandArgument.ToString());

if(index<0)
{
return;
}

GridViewRow row = GridView1.Rows[index];

var text = GridView1.Rows[index].Cells[0].Text;

string tb = ((TextBox)GridView1.Rows[index].FindControl("txt1")).Text;

String[] sentences = Regex.Split(text, @"(?<=[.!?])\s+(?=\p{Lt})");

System.Data.DataTable dt1 = new System.Data.DataTable();

dt1.Columns.Add("SentenceText1");

foreach (string value in sentences)
{
if(!string.IsNullOrWhiteSpace(value))
dt1.Rows.Add(value);
}
SqlConnection con = new SqlConnection(conn);
con.Open();
string sql = "";
for (int i = 0; i < dt1.Rows.Count; i++)
{
sql = sql + "INSERT INTO Sentences(SentenceText) SELECT '" + dt1.Rows[i]["SentenceText1"].ToString() + "' FROM Sentences WHERE NOT EXISTS(SELECT '" + dt1.Rows[i]["SentenceText1"].ToString() + "' FROM Sentences WHERE SentenceText='" + dt1.Rows[i]["SentenceText1"].ToString() + "')";
sql = sql + "";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}
vatsaldesai 5-Mar-15 2:24am    
i have store value of dt1.Rows[i]["SentenceText1"].ToString() in one variable name abc and how can use this variable name abc in store procedure as input parameter to insert that variable's value.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900