Home All Groups Group Topic Archive Search About

Insert into Empty table problem

Author
21 Jun 2006 11:29 AM
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()


Author
21 Jun 2006 11:42 AM
Miha Markic [MVP C#]
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/

Show quote
"sun919" <u23205@uwe> wrote in message news:62184bdab9ca0@uwe...
> 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
> http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-ado-net/200606/1
Author
21 Jun 2006 3:37 PM
sun919 via DotNetMonster.com
Thanks u @idenity is not suppose to output  so i remove that.....  but try to
remove that and it still doesnt work ....


Miha Markic [MVP C#] wrote:
Show quote
>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()

Author
21 Jun 2006 6:12 PM
Miha Markic [MVP C#]
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" <u23205@uwe> wrote in message
news:621c2cd32997a@uwe...
Show quote
> Thanks u @idenity is not suppose to output  so i remove that.....  but try
> to
> remove that and it still doesnt work ....
>
>
> Miha Markic [MVP C#] wrote:
>>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()
>
> --
> Message posted via DotNetMonster.com
> http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-ado-net/200606/1
Author
22 Jun 2006 5:40 AM
sun919 via DotNetMonster.com
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



Miha Markic [MVP C#] wrote:
>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]
>>>>
>>>>            con2.Close()

--
Message posted via http://www.dotnetmonster.com

AddThis Social Bookmark Button