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 the importance of Global.asax in ASP.NET?

763


How u refer webservices?

1683


What is the concepts of globalization and localization in .net?

721


What is css in asp.net?

768


what is meant by sitemapnode ?

1737


How to disable validator control by client side JavaScript?

750


What is a postback in asp net?

794


What is custom events? How to create it?

817


What is a url string?

790


In What Order Do The Events Of An Aspx Page Execute. As A Developer Is It Important To Undertsand These Events?

788


What are the Types of chaching. How to implement caching

764


Differentiate between a hyperlink control and a linkbutton control.

727


Do gac'ed assemblies have fulltrust?

846


how to elimainte the similar data from the different tables

1897


How does a web application session work?

779