c# - Update one table and insert into another table in SQL Server 2008 -


The company with {Company ID} has a combination of two tables (Auto Incharge Primary Key) and Group ID (Auto Informant Primary Key).

In the group table, I want to include group details on the group table with the group id inserted in the group table, along with updating the group column of the company table and submitting the button. Please suggest me how to do this with different orders or through stored procedures. I'm a little weak with SQL Server queries so with some clarification some help is needed. What I'm doing wrong is what gives wrong syntax to the keyword "inner". thank you in advanced.

company table

 group table

Submit button on web form

submit button click code:

  secure void btnSubmit_Click (object sender, EventArgs e) {string group = GroupName text; String section = section. Text; String company = session ["com"]. Toasting (); If ((HttpContext.Current.User! = Null) & amp; amptt; HTTPXx.Current.Under.indenti.authorized & amp; company! = Faucet) {String StrCon = Configuration Manager.Connection Strings ["Local SQL Server"] . ConnectionString; SqlConnection con = new SqlConnection (stren); Con.Open (); Dataset DS = new dataset (); SqlDataReader rdr = null; SqlCommand cmd1 = New SQL Commands ("Group (GroupName, Department, Company ID) value (@ group name, @ department, select company ID from company company where company.companyname = @ companyName ')", conn.); SqlCommand CMD = New SQL Commands ("Update company 1 set company 1. group = group group.Ind is included on the group on Inner Group. Companie ID = COMPANY 1. COMPANIYID" + "where company.companyname = @ companyName", Who); Cmd1.Parameters.Add ("Group name", SqlDbType.NVarChar) .Value = Group; Cmd1.Parameters.Add ("Department @", SqlDbType.NVarChar) .Value = dept; Cmd1.Parameters.Add ("Company Name", SqlDbType.NVarChar) .Value = Company; Cmd.Parameters.Add ("Company Name", SqlDbType.NVarChar) .Value = company; //cmd1.Parameters.AddWithValue("@groupName ", group); //cmd1.Parameters.AddWithValue (@@@ department), department); //cmd.Parameters.AddWithValue("@companyName ", Company); Rdr = cmd1.ExecuteReader (); RRR = CMD. Spare reader (); Con.Close (); } Else {Response.Redirect ("account / login .aspx"); }}    

In the context of this comment:

In the company, GroupID is taken as NIHARAARA (30) in order to separate the separate groupings by commas, how can I get this?

The answer is no. You are repeating the data, while accumulating a relationship, a delimited string never is not a good idea in the relational database, it defeats the purpose.

I think that in whatever you have to do, enter CompanyID at the same time while adding the group.

  Select INSERT Dbo.Group (GroupName, Department, Customer ID) @ group name, @department, c. CompanIID FOr dbo.Company1 ASC WHERE c.CustomerName = @CustomerName;   

Then your C # will look like the end:

  string sql = @ "INSERT dbo. [Group] (group name, department, customer id) SELECT @ GroupName, @Departmentment, C.companyIDFDO.O.CompAN1ACCWHERE c.CompanyName = @CompanyName; "; String strang = configuration manager. Connection strings ["local escal server"]. (Var connection = New SqlConnection (stren)) using (var command = new SQL command (SQL, connection)) {connection.Open (); Command.Parameters.Add (@GroupName, SqlDbType.NVarChar, 50) .Value = Group; Command. Parameter. Ed (@Department, SKLDB type.NVarChar, 50). Value = deputy; order. Parameter. Add (@company name, SqlDbType.NVarChar, 50). Value = company; command.ExecuteNonQuery (); }   

ExecuteNonQuery () instead of using ExecuteReader () , because you are not actually reading anything , And its use by using to block to ensure that your objects are correctly resolved I have schema in your queries (which is assumed to be dbo ) The prefix is ​​also included

If you have to group the groups associated with a particular company in a query, each NSERT / UPDATE / DELETE :

  Select c.CompanyID, c.CompanyName, with groups = STUFF to avoid the repetition of  groups  VARCHAR (10) as the GroupG (in the form of Group) [Group] ASG GERE G. CompanieID = C. CompanID for xml path ('', tiepe) Price ('.', 'NVRAR (Max)'), 1, 1, ''). Deborah. Company ASC;   

For adding more information to the rows in the column;

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -