C# Tutorials and offshore development in India
Tutorials Resources Forum Reviews Communities Interview Jobs Projects Training Your Ad Here


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Visual Studio »

Insert records in vb,net


Posted Date: 17 Nov 2009      Posted By: kumari      Member Level: Silver     Points: 1   Responses: 5



I have sqlserverce database.In this database i have 2 tables.the tables are
1)UserTable
2)Information table.
In userTable i have 2 columns they are DomainId,Domain Name.
In Information table i have 3 columns they are UserId,Domain Name,Application.
I want the following code.
1)I want to insert data i.e UserTable field Domain Name value added to Information Table field Domain Name.
How to do in vb.net





Responses

Author: Alwyn    17 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

u can do this

@DomainName VARCHAR(50)

INSERT INTO UserTable(DomainName)
Values (@DomainName )
Insert Into InformationTable(DomainName)
Values (@DomainName)

So simple.

Regards,
Alwyn Duraisingh.M
Jesus saves! The rest of us better make backups.
My Blog



Author: Nagarajan    17 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

you have to use Transaction for inserting two tables at a time..

Try this
SqlTransaction Trans
con.open()
string str = "insert into tbl1 values('"+ asdfs+"')"
string str1 = "insert into tbl2 values('" + dfdsfd +"')"

sqlcommand cmd = new sqlcommand (str,con);
cmd.Transaction = Trans
cmd.ExecuteNonQuery()

sqlcommand cmd1 = new sqlcommand (str1,con)
cmd1.Transaction = Trans
cmd1.ExecuteNonQuery()

Trans.commit()
con.close()

Regards,

Naresh

Don't Scream for a Change... Become a Change..

Do not forget to Rate the post..



Author: Dharmaraj    17 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi,
For inserting the record for the user table

SqlConnection con = new SqlConnection("your connection string");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText="INSERT INTO userTable(DomainId,DomainName) VALUES('" + did + "' , '" + dname + "')
cmd.ExecuteNonQuery();
// The records will get inserted in to the domain table
// similarly while inserting the record in the domain table
// you can create another command object
// you can insert the values in the user table.


Regards,
Dharma
Editor,Mentor,MVM
Try and fail but don't fail and try
Me and DNS



Author: Ankur    17 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

use an stored procedure for it rather doing on front end ,it will save your server trip and increase the performance of your site

Regards
Ankur

Dont forget to rate it if it help



Author: kumari    17 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

I used the following code..in vb.net code its working.but the values are added to the Sqlsevercetable i.e usertable
Dim cmnd As SqlCeCommand = New SqlCeCommand(sqlstring, MyConnection)
cmnd = New SqlCeCommand("insert into UserInformation([UserId],[DomainName]) Values ('" & userrow.UserId & " ', '" & userrow.DomainName & "')", MyConnection)
Dim insertdata As Integer = cmnd.ExecuteNonQuery()



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Gridview update parameter
Previous : Please help me on C#
Return to Discussion Forum
Post New Message
Category: Visual Studio

Related Messages




About Us    Contact Us    Privacy Policy    Terms Of Use