detail code for sql data connections?

Answer Posted / bhagwat prasad sharma

Steps: SqlConnection with vb.net code
'' Code

imports system.data.sqlclients
Public Class Form1 Inherits System.Windows.Forms.Form
'' createconnection with database

dim con as new sqlconnection("server=bps; database=company; user id=sa; password=admin")

private sub button1_click()

dim str as string="insert into employee (roll_no,name,class) values(@roll_no,@name,@class)"

dim cmd as new sqlcommand =(str,con)

if con.state=connectionstate.closed than
con.open()
'' parameter passing

cmd.parameters.add("@roll_no",type.int)
cmd.parameters.add("@name",type.varchar)
cmd.parameters.add("@class",type.varchar)

cmd.parameters("@roll_no").value= txtroll.text
cmd.parameters("@name").value=txtname.text
cmd.parameters("@class").value= txtclass.text

dim i as integer
i=cmd.executeNonquery

if i>o
msgbox("addition successful")
else
msgbox("sum mistakes into add")
end if
' end of connection
con.close()
end sub
end class

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is cookieless session id explain in brief?

521


Explain the asp.net mvc request life cycle? : asp.net mvc

489


How do I know asp.net mvc version? : Asp.Net MVC

485


Why we use content place holder in asp.net?

488


Write a code for passing ArrayList in Web API?

1042






What are the features of asp net?

503


What are the different types of validation controls provided in ASP.NET?

654


How is it possible for .NET to support many languages?

289


What are the namespace classes used in asp.net mvc? : asp.net mvc

530


What is the use of service provider?

574


What are server objects?

505


In asp.net, how can you validate drop down box?

576


Write some code using interfaces, virtual methods, and an abstract class`

1570


What are the two Layouts supported by a Web form in ASP.NET?

543


What r the asp.net list controls and difference between them?

498