PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Insert into Empty table problem

Reply

Insert into Empty table problem

 
Thread Tools Rate Thread
Old 21-06-2006, 12:29 PM   #1
sun919
Guest
 
Posts: n/a
Default Insert into Empty table problem


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/Fo...do-net/200606/1
  Reply With Quote
Old 21-06-2006, 12:42 PM   #2
Miha Markic [MVP C#]
Guest
 
Posts: n/a
Default Re: Insert into Empty table problem

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/

"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/Fo...do-net/200606/1



  Reply With Quote
Old 21-06-2006, 04:37 PM   #3
sun919 via DotNetMonster.com
Guest
 
Posts: n/a
Default Re: Insert into Empty table problem

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/Fo...do-net/200606/1
  Reply With Quote
Old 21-06-2006, 07:12 PM   #4
Miha Markic [MVP C#]
Guest
 
Posts: n/a
Default Re: Insert into Empty table problem

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...
> 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/Fo...do-net/200606/1



  Reply With Quote
Old 22-06-2006, 06:40 AM   #5
sun919 via DotNetMonster.com
Guest
 
Posts: n/a
Default Re: Insert into Empty table problem

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
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off