Insert into Empty table problem

  • Thread starter Thread starter sun919
  • Start date Start date
S

sun919

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()
 
Thanks u @idenity is not suppose to output so i remove that..... but try to
remove that and it still doesnt work ....

Is @Identity an output parameter of your InsertReligion stored procedure?
hi there,
I have problem regarding insert data into empty table. i have two fields
[quoted text clipped - 33 lines]
con2.Close()
 
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/

sun919 via DotNetMonster.com said:
Thanks u @idenity is not suppose to output so i remove that..... but try
to
remove that and it still doesnt work ....

Is @Identity an output parameter of your InsertReligion stored procedure?
hi there,
I have problem regarding insert data into empty table. i have two fields
[quoted text clipped - 33 lines]
con2.Close()
 
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


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.
Thanks u @idenity is not suppose to output so i remove that..... but try
to
[quoted text clipped - 7 lines]
 
Back
Top