Click here to Skip to main content
16,015,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have one DataSet like
sno name qty
1 a 10
And another DataSet
Sno CurrentStock
1 50
My actual requirement is I want to check the sno '1' in first dataset is available in second dataset if it is available I want to update qty from first dataset to table

And sno 1 is not available in second dataset I need to insert a new record in table

Please help me


Thanks in advance
Posted
Updated 16-Jun-12 19:36pm
v2
Comments
OriginalGriff 17-Jun-12 1:44am    
And what is giving you a problem with this?
What have you tried?
Use the "Improve question" widget to edit your question and provide better information.

Hello,
I thought that you want this type of code like here...

C#
SqlDataAdapter adp = new SqlDataAdapter("select * from tbl1", cn);
       DataSet ds = new DataSet();
       adp.Fill(ds);

       SqlDataAdapter adp1 = new SqlDataAdapter("select * from tbl2", cn);
       DataSet ds1 = new DataSet();
       adp1.Fill(ds1);

       if (ds.Tables[0].Rows[0][0].ToString()==ds1.Tables[0].Rows[0][0].ToString())
       {
           SqlCommand cmd = new SqlCommand("insert into tbl1 values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')", cn);
           cn.Open();
           cmd.ExecuteNonQuery();
           cn.Close();

           SqlCommand cmd1= new SqlCommand("insert into tbl2 values('" + TextBox1.Text + "','" + TextBox3.Text + "')", cn);
           cn.Open();
           cmd1.ExecuteNonQuery();
           cn.Close();
       }
 
Share this answer
 
v2
Hello,

Just wanted to improve the above solution.

Instead of using this check
C#
if (ds.Tables[0].Rows[0][0].ToString()==ds1.Tables[0].Rows[0][0].ToString())
       {}


use

C#
string compare = ds1.Tables[0].Rows[0][0].ToString();
if(ds.Tables[0].DefaultView.RowFilter = "SNo ='"+compare+"'")
{}


Row filter will check the value in all the row, not only in row whoes index is provided (Rows[0][0])
 
Share this answer
 

this is custom big ..y
 
Share this answer
 
Comments
Nelek 15-Apr-13 6:48am    
??????????
fjdiewornncalwe 15-Apr-13 9:54am    
I think he means "this is custom big ... mistake..."

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