Groups | Blog | Home
all groups > dotnet ado.net > june 2006 >

dotnet ado.net : Insert into Empty table problem


sun919
6/21/2006 11:29:50 AM
hi there,
I have problem regarding insert data into empty table. i have two fields
which is religionID and ReligionName
i have try to insert data that generate use @@identity inorder to find and
create id no. and it still doesnt work and i have try to do insert and update
into table and still nothing is adding to the table. I m using sql server for
the database this is what my insert and update into table look like



Dim catDA As SqlDataAdapter = New SqlDataAdapter("SELECT ReligionID,
ReligionName FROM ReligionType", con2)

catDA.InsertCommand = New SqlCommand("InsertReligion", con2)
catDA.InsertCommand.CommandType = CommandType.StoredProcedure

catDA.InsertCommand.Parameters.Add("@ReligionName", SqlDbType.
NVarChar, 20, "ReligionName")

Dim myParm As SqlParameter = catDA.InsertCommand.Parameters.Add
("@Identity", SqlDbType.Int, 0, "ReligionID")
myParm.Direction = ParameterDirection.Output

Dim catDS As DataSet = New DataSet
catDS.Locale = New System.Globalization.CultureInfo("th-TH")

con2.Open()


catDA.Fill(catDS, "ReligionType")

Dim newRow As DataRow = catDS.Tables("ReligionType").NewRow()
newRow("ReligionName") = inputdata.Text
catDS.Tables("Religion").Rows.Add(newRow)

catDA.Update(catDS, "ReligionType")

con2.Close()

--
Message posted via DotNetMonster.com
Miha Markic [MVP C#]
6/21/2006 1:42:17 PM
Is @Identity an output parameter of your InsertReligion stored procedure?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]

sun919 via DotNetMonster.com
6/21/2006 3:37:29 PM
Thanks u @idenity is not suppose to output so i remove that..... but try to
remove that and it still doesnt work ....


[quoted text, click to view]

--
Message posted via DotNetMonster.com
Miha Markic [MVP C#]
6/21/2006 8:12:59 PM
How would it work as your stored procedure doesn't return new identity?
You should add output identity (i.e. @newId) parameter to your stored proc
and catch it at the client side.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]

sun919 via DotNetMonster.com
6/22/2006 5:40:59 AM
i ve change it to output as correct and this is my stored procedure

ALTER PROCEDURE InsertReligion
@ReligionName nvarchar(20), @Identity int OUT
AS
INSERT INTO ReligionType (ReligionName) VALUES(@REligionName);

SET @Identity = Scope_Identity();
RETURN @@ROWCOUNT

is it because it is empty table so this mean rowcount = 0 ? if that so how do
i come about .. cause i try to put if statement in stored procedure and it
doesnt help at all
many thanks
sun



[quoted text, click to view]

--
AddThis Social Bookmark Button