PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Insert into Empty table problem
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Insert into Empty table problem
![]() |
Insert into Empty table problem |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

