473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid Insert Statement

I AM GETTING A SYSTEM.DATA.SQL CLIENT.SQLEXCEP TION ERROR WHEN ATTEMPTING TO
INSERT DATA INTO A SINGLE TABLE THROUGH A GRID
//If this is due to a spelling error, i will
//inflict a ritual beating upon myself !!!!!!!!!!!!

TABLE SCRIPT

/* 04 September 2004 03:15:04 User: Server: (local) Database:
Payslip Application: MS SQLEM - Data Tools*/BEGIN TRANSACTION
SET QUOTED_IDENTIFI ER ON
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
SET ARITHABORT ON
SET NUMERIC_ROUNDAB ORT OFF
SET CONCAT_NULL_YIE LDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_Allowan ces
(
AllowanceID int NOT NULL IDENTITY (1, 1),
AllowanceDesc nvarchar(50) NULL,
AllowanceAmt decimal(19, 4) NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT dbo.Tmp_Allowan ces ON
GO
IF EXISTS(SELECT * FROM dbo.Allowances)
EXEC('INSERT INTO dbo.Tmp_Allowan ces (AllowanceID, AllowanceDesc,
AllowanceAmt)
SELECT AllowanceID, AllowanceDesc, AllowanceAmt FROM dbo.Allowances
TABLOCKX')
GO
SET IDENTITY_INSERT dbo.Tmp_Allowan ces OFF
GO
DROP TABLE dbo.Allowances
GO
EXECUTE sp_rename N'dbo.Tmp_Allow ances', N'Allowances', 'OBJECT'
GO
ALTER TABLE dbo.Allowances ADD CONSTRAINT
PK_Allowances PRIMARY KEY CLUSTERED
(
AllowanceID
) ON [PRIMARY]

GO
GRANT SELECT ON dbo.Allowances TO public AS dbo
GRANT UPDATE ON dbo.Allowances TO public AS dbo
GRANT INSERT ON dbo.Allowances TO public AS dbo
GRANT DELETE ON dbo.Allowances TO public AS dbo
COMMIT


THIS IS THE CODE USED TO PERFORM THE INSERT, THE UPDATE,DELETE AND SELECT
WORKS FINE


//Populate allowances datagrid
// *************** *************** ALLOWANCES
*************** *************** **

SqlConnection connGetAllowanc es = new SqlConnection(
"data source=chrisnot e;initial catalog=Payslip ;integrated
security=SSPI;p ersist security info=False;work station id=CHRISNOTE;") ;
dsModify = new DataSet();
daModify = new SqlDataAdapter( );
//Get the data
SqlCommand cmdSelect = connGetAllowanc es.CreateComman d();
cmdSelect.Comma ndType = CommandType.Tex t;
cmdSelect.Comma ndText = "SELECT AllowanceID," +
" AllowanceDesc,A llowanceAmt FROM Allowances";

// *************** *************** ** Insert data
SqlCommand cmdInsert = connGetAllowanc es.CreateComman d();
cmdInsert.Comma ndType = CommandType.Tex t;
cmdInsert.Comma ndText = "INSERT INTO Allowances " +
"(Allowance ID, AllowanceAmt, AllowanceDesc)" +
"VALUES (@AllowanceID, @AllowanceAmt,@ AllowanceDesc)" ;

//Create insert parameters
cmdInsert.Param eters.Add("@All owanceID",SqlDb Type.Int,4,"All owanceID");
cmdInsert.Param eters.Add("@All owanceAmt",SqlD bType.Decimal, 9,"AllowanceAmt ");
cmdInsert.Param eters.Add("@All owanceDesc",Sql DbType.NVarChar ,
50,"AllowanceDe sc");
cmdInsert.Param eters["@Allowance ID"].SourceVersion = DataRowVersion. Original;

//Set the dataadapter and fill the dataset

daModify.Select Command = cmdSelect;
daModify.Update Command = cmdUpdate;
daModify.Insert Command = cmdInsert;
daModify.Delete Command = cmdDelete;

daModify.Fill(d sModify, "Allowances ");
//Bind the datasources to the datagrid
dgAllowances.Da taSource = dsModify;
dgAllowances.Da taMember = "Allowances ";

THE FOLLOWING CODE IS MEANT TO UPDATE THE TABLE
private void btnAcceptManage Changes_Click(o bject sender, System.EventArg s e)
{

daModify.Update (dsModify, "Allowances ");
}


Is there anywhere that i can get sample code of how to
populate, edit, add new and delete data from a datagrid ?
Thanks
Christopher

Nov 16 '05 #1
0 2200

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
432
by: adove | last post by:
I am having problems with the following code. I am trying to update my db table Categories in Northwind. I have borrowed this code from www.dotnetjohn.com/articles/articleid27.aspx Although it works on dotnetjohn website, I cannot replicate the code successfully. I have a datagrid filled with data and two textboxes with an “Insert” button....
10
1658
by: GML | last post by:
I have a bound datagrid in C# based on an an SQL query. The results are displayed in a Sharepoint 2003 Webpart. I would like to add a new column based on the results of two columns in the datagrid. It is not possible for me to do this within the SQL query as the data provider I am using does not support column alias's. e.g. Put the results...
7
2688
by: Pierluigi Terzoli | last post by:
Hi everybody, I need help for this problem: I'm using a DataGrid to Insert/Modify/Cancel data from a single table. At the moment, every cell modification of a pre-existing row is correctly update on the DB. I have some doubts about inserting a new row. The table has a Id field that is a primary key defined ad Identity properties on...
8
1706
by: Brent Burkart | last post by:
My datagrid OnCancelCommand event is not firing. HTML OnCancelCommand="AdminGrid_Cancel" 'Code Behind Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) AdminGrid.EditItemIndex = -1 BindData()
9
5044
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ******************************************************************************* <asp:DataGrid visible="False" border=1
2
267
by: Channa | last post by:
I have a datagrid that is bound to an MSDataSetGenerator that is then bound to an access database though a OleDbDataAdapter and an OleDbConnection. I am able to open the form and its datagrid with no problem. My question is no I want the underlaying sql statement to be able to be based on a variable. In other words my sql statement is:...
4
4526
by: jaYPee | last post by:
I have 1 dataset called "dataset1" that contains 2 tables called "course" and "courseload". in my form i have a datagrid. the datasource of this datagrid is "dataset1" and the datamember is "courseload". here's the fields of every table in my dataset. "Course" table CourseID
12
6196
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my...
1
1557
by: sandeep.damodar | last post by:
Hello, I need help.. I am just trying to insert data from the datagrid to data source, using insert sql statement.
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.