473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to insert multiple records in Items table but only one in Master table

public void InsertPlannedMaterialMasterRequest(int id, string requestDocument, string requestDescription, string requestType, string hodApproval, int companyCode, string hodRemarks, string det_Description, string name, int qty, string code)
{
string query = "INSERT INTO MasterRequest (ID,Req_Document,Req_Description,ReqType,HODApprov al,CompanyCode,HODRemarks) VALUES (@ID,@Req_Document,@Req_Description,@ReqType,@HODA pproval,@CompanyCode,@HODRemarks)";

SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.Add("@ID", SqlDbType.Int).Value = id;
com.Parameters.Add("@Req_Document", SqlDbType.NVarChar).Value = requestDocument;
com.Parameters.Add("@Req_Description", SqlDbType.NVarChar).Value = requestDescription;
com.Parameters.Add("@ReqType", SqlDbType.NVarChar).Value = requestType;
com.Parameters.Add("@HODApproval", SqlDbType.NVarChar).Value = hodApproval;
com.Parameters.Add("@CompanyCode", SqlDbType.Int).Value = companyCode;
com.Parameters.Add("@HODRemarks", SqlDbType.NVarChar).Value = hodRemarks;

con.Open();
com.ExecuteNonQuery();
con.Close();


string query2 = "INSERT INTO DetailRequest (ID,Req_Document,Description,Approval) VALUES (@ID,@Req_Document,@Description,@Approval)";
SqlConnection con2 = new SqlConnection(constr);
SqlCommand com2 = new SqlCommand(query2, con2);
com2.Parameters.Add("@ID", SqlDbType.Int).Value = id;
com2.Parameters.Add("@Req_Document", SqlDbType.NVarChar).Value = requestDocument;
com2.Parameters.Add("@Description", SqlDbType.NVarChar).Value = det_Description;
//com2.Parameters.Add("@Quantity", SqlDbType.Int).Value = qty;
//com2.Parameters.Add("@UOM", SqlDbType.NVarChar).Value = unitOfMeasure;
com2.Parameters.Add("@Approval", SqlDbType.NVarChar).Value = hodApproval;

con2.Open();
com2.ExecuteNonQuery();
con2.Close();

string query3 = "INSERT INTO ITEMS (ID,Code,Name,Quantity) VALUES (@ID,@Code,@Name,@Quantity)";
SqlConnection con3 = new SqlConnection(constr);
SqlCommand com3 = new SqlCommand(query3, con3);
com3.Parameters.Add("@ID", SqlDbType.Int).Value = id;
com3.Parameters.Add("@Code", SqlDbType.NVarChar).Value = code;
com3.Parameters.Add("@Name", SqlDbType.NVarChar).Value = name;
com3.Parameters.Add("@Quantity", SqlDbType.Int).Value = qty;

con3.Open();
com3.ExecuteNonQuery();
con3.Close();


}

//Now following is the code I am using in my PlannedmterialRequest.aspx.cs

protected void Button1_Click(object sender, EventArgs e)
{
MasterRequest_DAL helper = new MasterRequest_DAL();

PlannedMaterialRequest pnd = new PlannedMaterialRequest();
ItemsHandling itm = new ItemsHandling();

string[] labelName = new string[100];
string[] coder = new string[100];
string[] quantity = new string[100];


if (TextBox6.Text != "0")//if quantity entered into Capacitor textBox
{
labelName[1] = itm.Code(0).ToString();
labelName[2] = TextBox6.Text;
helper.InsertPlannedMaterialMasterRequest(Convert. ToInt32(TextBox1.Text), TextBox2.Text, TextBox4.Text, DropDownList6.SelectedValue, DropDownList2.SelectedValue, Convert.ToInt32(TextBox11.Text), TextBox12.Text, TextBox13.Text, Label8.Text, Convert.ToInt32(TextBox6.Text), labelName[1]);


}

if (TextBox12.Text != "0")//if quantity entered into Wires textBox
{
//labelName(0) needs to be commented
//labelName[0] = pnd.Label8.Text.ToString();
labelName[1] = itm.Code(1).ToString();
labelName[2] = TextBox12.Text;
helper.InsertPlannedMaterialMasterRequest(Convert. ToInt32(TextBox1.Text), TextBox2.Text, TextBox4.Text, DropDownList6.SelectedValue, DropDownList2.SelectedValue, Convert.ToInt32(TextBox11.Text), TextBox12.Text, TextBox13.Text, Label12.Text, Convert.ToInt32(TextBox8.Text), labelName[1]);



}
}

The problem I am facing is that using the above code. The ID goes multiple times in MasterRequest table which should go only once, while the same ID must go to Items table multiple times as per the quantities being entered. I want only the ID to go into MasterRequest table just once not multiple times.
Attached Images
File Type: jpg untitled.jpg (20.2 KB, 224 views)
May 22 '10 #1
1 2119
nukefusion
221 Expert 100+
@omaragainonthetrack
Hi omaragainonthetrack,

Welcome to the forums.

To help your question to get answered, please take a look at the Posting Guidelines.

It will help us to help you if you reformat your post using code tags. It makes it much easier to read. It might be helpful as well if you post the question before the code sample.

Kindest regards,
Matt.
May 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brian | last post by:
I need help PLEASEEEEEEEEEEEEEEE..... I am trying to create a list of questions that have yes/no answers. There are 8 groups of questions. Based on who the user is that logs in will determine...
4
by: Terren | last post by:
Is there a way to create one field from multiple records using sql. For example Table 1 John 18 Peter 18 David 18 Now I want an sql query that when executed will return a field that...
2
by: kokul_k | last post by:
Hi.. I'm facing a problem during inserting records in Mysql database. My table consists of 9 fields. When i try to insert 1000 records to this table using for loop it takes a lot of time.. nearly...
3
by: Alvin SIU | last post by:
Hi all, I am using DB2 in AIX. I have a master table and a txn table. The master table has many many records. Each month, there is a new txn table.
7
by: flashguy | last post by:
Hi, Looking online for this related topic that will be exclusively used for MS ACCESS (2000 preferably) is extremely limited. Is it possible to add Multiple records with one click of a buttton...
2
by: tamimmakki | last post by:
hi, i have to add names of 11 players of a team into database table 'tbl_players'. so i put 11 text boxes in form with a submit button. I tried it with a for loop but its not working. I am working in...
0
by: t8ntboy | last post by:
ASP/SQL Server Express 05 I have two tables, A and B. I would like to insert multiple records into both form A and B, but a field in form B is the Record ID in form A. So, I need to insert the...
1
by: xixor | last post by:
I work for a nonprofit organization that allows individuals to sponsor children overseas. Some of these sponsors decide to become volunteers and speak at their church, university, or other event to...
1
by: sreenu123 | last post by:
How to insert multiple records into a database table that are entered into a datagridview. With a single shot of Save all the records in the datagridview should be updated using C# . Can any one help...
2
by: phill86 | last post by:
Hi, i have a recordset that updates a table which works fine when you add, update and paste a single record but if you try and paste multiple records it will only update the table with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.