Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 29th, 2004, 06:29 AM
Registered User
 
Join Date: Mar 2004
Location: Lahore, , Pakistan.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to simsimlhr Send a message via Yahoo to simsimlhr
Default Why normal insert querry doesnot work

I made connection with sql Server 2000.When Write Normal add querry
I gives error.Remember Insertion is in table.But When i write following code it works.

System.Data.SqlClient.SqlCommand
sqlInsertCommand1.CommandText="INSERT INTO Student(id) VALUES (@id)";
System.Collections.IEnumerator a=sqlInsertCommand1.Parameters.GetEnumerator();
a.MoveNext();
SqlParameter myParm=(System.Data.SqlClient.SqlParameter)a.Curre nt;
myParm.Value='12';
sqlInsertCommand1.ExecuteNonQuery();


I donot know why is so.Further more similar code for delete require all parameter in condition of delete querry.Thats not feasible.Can anybody tell me what is the problem.Why normal querry doesnot work.

  #2 (permalink)  
Old April 22nd, 2004, 06:10 AM
Authorized User
 
Join Date: Apr 2004
Location: pta, Gauteng, South Africa.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi (just joined today!!!)

System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(strConnectStri ng);
System.Data.SqlClient.SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "Insert into Clients(ClientID,Name,Surname,IDNo,PostalAddress,R esidentialAddress,
HomeTel," +
"Mobile,Remarks,BankName,BranchName,BranchCode,Acc ountNumber,
CardNumber," +
"ExpDate,PIN,TypeAccount,EmpNumber,Department,PayD ate,NettSal,EmployersID,UserID,Borrowing_Limit,Bla ckList)" +
"values('" + txtClientNum.Text + "','" + txtCustName.Text + "','"
+ txtSurname.Text + "','" + txtCustID.Text + "','" + txtPostal.Text + "','"
+ txtResid.Text + "','" + txtMobile.Text + "','"
+ txtHomeTel.Text + "','" + txtRemarks.Text + "','"
+ txtBankName.Text + "','" + txtBranch.Text + "','"
+ txtBranchCode.Text + "','" + txtAccNum.Text + "','"
+ txtCardNum.Text + "','" + txtExpDate.Text + "','"
+ txtPIN.Text + "','" + cbAccTypes.Text + "','"
+ txtEmpNum.Text + "','" + txtDept.Text + "','"
+ cbPayDate.Text + "','" + txtNettSal.Text + "','"
+ lblEmpID.Text + "','" + lblUsID.Text + "','" + txtBorrowLimit.Text + "','" + blacklist + "')";
cmd.CommandType = System.Data.CommandType.Text;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();

This should work. The plus signs are for concatenation purposes.
This is the actual query that I use and it works everytime

jan

dude_in_africa
  #3 (permalink)  
Old January 9th, 2006, 03:26 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have table name Id in which Id is the primary key.
I have one another table name Size ,I want to insert the values in size table for the value of field Id in Id table, So please tell me my Insert querry is of what type which makes joint of two table. by the way I am using access database
Please help me




Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't this Insert Procedure work. beerOne ASP.NET 3.5 Basics 2 June 19th, 2008 09:59 AM
Insert won't work Tod1 Access VBA 1 December 18th, 2006 10:50 PM
Problem with insert querry Ashwini Classic ASP Databases 0 January 16th, 2006 07:17 AM
insert tigger dont work multiple kspiderman SQL Server 2000 1 October 21st, 2005 01:42 PM
Insert method doesnot work shoakat Classic ASP Databases 3 November 22nd, 2004 07:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.