Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
0 down vote favorite


I have two table are as follows.

1- Table name: Action01

ID Label01
1 Orange
2 Mango
3 Lemon

2- Table Name:- Action02

ID Label02
1 05 qty
2 10 Qty
3 06 Qty

These two table get the values on data entering on server

I want to add the values into new table name: PurchaseList

3: Tablename: PurchaseList

ID Purchasing
1 Orange, 05 qty
2 Mango, 10 qty
3 Lemon, 06 qty

Can anybody tell me how to add the above two coloumn(Label 01 and Label 02) into new table coloumn(purchasing) .

Purpose is to show purchasing coloum value into the textbody of front page and then later it will be use in my SQL reporting.


See links for other comments in stackflow which is still not solved!

http://stackoverflow.com/questions/24365627/adding-value-of-two-table-into-new-table-aspnet-c-sharp-webform/24365707?noredirect=1#comment37756364_24365707[^]



Regards Tahir
Posted
Comments
_Asif_ 25-Jun-14 7:56am    
Share your code and connection string to database
tahirgr8_2000 25-Jun-14 8:04am    
First Page for storing value into table action 01


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.Linq;



public partial class _1a: System.Web.UI.Page
{ private string Status1A;
private string Status1B;
private string Status1C;
private string Status1D;
private string action1a;

private string StrInsert;
private SqlCommand Sql;
private SqlConnection hookUp;
protected void Page_Load(object sender, EventArgs e)
{
Status1A += Checkbox1.Checked == true ? Checkbox1.Value : null;
Status1B += Checkbox2.Checked == true ? Checkbox2.Value : null;
Status1C += Checkbox3.Checked == true ? Checkbox3.Value : null;
Status1D += Checkbox4.Checked == true ? Checkbox4.Value : null;

action1a += Status1A + Status1B + Status1C + Status1D + TextBox1;
}

protected void Button1_Click(object sender, EventArgs e)
{
hookUp = new SqlConnection("Server=localhost\\Sqlexpress; Database=ActionTakenDB;" + "Integrated Security=True");
StrInsert = "insert into Action1A values (@Action1a)";
Sql = new SqlCommand(StrInsert, hookUp);
Sql.Parameters.Add(new SqlParameter("@Action1a", SqlDbType.VarChar, 100));
Sql.Parameters["@Action1a"].Value = action1a;
hookUp.Open();

Sql.ExecuteNonQuery();

hookUp.Close();
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
}
}


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="1a.aspx.cs" Inherits="_1a" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Checkbox1" type="checkbox" value="Pump seal replaced," runat="server" /> Pump seal replaced<br />
<input id="Checkbox2" type="checkbox" value="Bearing changed," runat="server" /> Bearing changed<br />
<input id="Checkbox3" type="checkbox" value="wiring proper," runat="server" /> wiring proper<br />
<input id="Checkbox4" type="checkbox" value="fuse replace" runat="server" /> fuse replace<br />
<input id="TextBox1" type="text" runat="server" /> Others <br />

<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
</div>

</form>
</body>
</html>





Now Second Page for storing value into Table ACtion02 continue in next comment

[no name] 7-Jul-14 1:04am    
create a dynamic table in your code and add column there also. put your values. But we could not clear any thing from your posted code

1 solution

You can do this by simple SQL Query by joining two tables by their Id and concatenating the two column values

For Example:

Table1
------
ID ItemName
1 Mango
2 Apple
3 Banana

Table2
------
ID ItemValue
1 100
2 200
3 150

In Sql write as

Select a.ID, a.ItemName+convert(b.ItemValue as varchar) as [ItemWithRate]
 
Share this answer
 

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