Senin, 02 Februari 2009

create an insert statement in tableadapter


I am going nuts over this. I have created a new dataset pane and dragged a table onto it. I have created a stored procedure in my sql database and want to use this to insert a record into the table when a button is clicked onmy windows form. HOW ? If I type Me. in my code I am prompted for the items in another dataset, but not this one - why ? I don't want to update all the fields in the table, just 2 so will be passing these parameters. Here's my simple sp

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER PROCEDURE [dbo].[spPHCR_AuditTrailLogin]
-- Add the parameters for the stored procedure here
@AU_NetworkId nvarchar(100)= 0,
@AU_DateOn datetime

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
INSERT INTO tblPHCR_AuditTrail
(AU_NetworkId, AU_DateOn)
VALUES (@AU_NetworkId,@AU_DateOn)
END


whilst dragging and dropping is often the easiest way - you will sometimes come unstuck.. I always try to create the reference to the table adapters in code. the following works when you hve created strongly typed datasets


Code:
Dim mds as datasetname = new datasetname
Dim ta as datasetnametableadapters.tableadaptername = new datasetnametableadapters.tableadaptername
'Now you can use the following to fill the table called Parts in the dataset
ta.Fill(mds.Parts)
'or if you have created a new query called InsertNewValue
ta.InsertNewValue(someparameter)


Doing it this way takes longer as you need to type the code, I prefer it as I find I only learn if I am doing something my self..
good luck with the rest of it

source :http://www.vbcity.com

-------------------------------------------------------

Trik Gambar Bergerak

Trik Gambar-dimouse

Trik hapus pwd mysql

Trik insertin to db

Trik jadi root dilinux

Trik jam-distatus-bar

Trik Koneksi-ke database

Trik Koneksi-msql-php

Trik lihat-database-mysql

Trik membahas-fungsi-else

Trik member-area