used test table definition on SqlServer2008r2 / verwendete Test Tabellen Definition auf sql2008r2:
USE [test]
GO
/****** Object: Table [dbo].[tTest] Script Date: 10/04/2013 09:38:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tTest](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) NULL
) ON [PRIMARY]
GO
created a table adpater by drag and drop the table from server explorer into an empty dataset / erzeugete mittels drag and Drop vom Server Explorer in ein leeres Dataset einen TabellenAdapter
created a winform and drag and drop the table adapter into it => creating a datagridview
ein windows form erzeugt und den Table Adapter hineingezogen => ein Datagridview erzeugt
1) insert first row by entering name "test" and click save=>
exec sp_executesql N'INSERT INTO [dbo].[tTest] ([name]) VALUES (@name)',N'@name nvarchar(4)',@name=N'test'
2)insert second row "Test2" and click save=>
exec sp_executesql N'INSERT INTO [dbo].[tTest] ([name]) VALUES (@name)',N'@name nvarchar(5)',@name=N'test2'
--added primary key to table to get update command & delete command into Table Adapter
Primärschlüssel hinzugefügt um Update und Delete Command beim Table Adapter hinzuzufügen
3) update first row from "Test" to "Test1":
exec sp_executesql N'UPDATE [dbo].[tTest] SET [name] = @name WHERE (([id] = @Original_id) AND ((@IsNull_name = 1 AND [name] IS NULL) OR ([name] = @Original_name)));
SELECT id, name FROM tTest WHERE (id = @id)',N'@name nvarchar(5),@Original_id int,@IsNull_name int,@Original_name nvarchar(4),@id int',@name=N'test1',@Original_id=1,@IsNull_name=0,@Original_name=N'test',@id=1
4) insert row 3:
exec sp_executesql N'INSERT INTO [dbo].[tTest] ([name]) VALUES (@name);
SELECT id, name FROM tTest WHERE (id = SCOPE_IDENTITY())',N'@name nvarchar(5)',@name=N'test3'
No comments:
Post a Comment