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

How can you use a custom controls in ASP.NET application?

616


Define a multilingual website?

618


Which control has default post back is enabled(true)?

693


Mention the execution process for managed code?

628


What are the contents of cookie?

672






How can we prepairing Interview

1977


What is query string?

661


Explain the difference between webfarm and webgardens in .net?

631


What is the procedure to handle the process request using mhpm events fired? : asp.net mvc

640


In the Repeater control which way you can edit?

727


How to retrieve user name in case of Window Authentication?

373


what is a .xap file? Explain with an example.

675


How can we access static variable?

720


What is server side routing?

577


14. What are your Future Plans for Swatz Oils GROUP U.K?

1850