CCCCCCC C C CC: C C C C

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Assignment of VB.

Net
Q1. Explain the working of CommandBuilder object by using DataAdapter
object in ADO.Net?
Ans: The Command object can execute SQL queries and stored procedures. SQL queries are
executed to return data in a DataSet or a DataReader object. SELECT, INSERT, UPDATE,
and DELETE SQL queries are used to to retrieve add, update and delete. A DataAdapter
generated using the VS .NET Integrated development Environment (IDE) has these queries.

The SQL SELECT command is a fairly easy one to construct. InsertCommand,


UpdateCommand, and DeleteCommand can get quite complicated in .NET because they
require complex parameter objects and often involve large lists of columns ADO.NET
provides a nice utility know as the CommandBuilder that automatically builds these
commands for you.

Working of Command Builder object by using Data Adapter object in ADO.Net

Step 1-:

Step 2-:

The Data Adapter object serves as a conduit between the data source and the
Dataset. The Data Adapter knows about the DataSet and it knows how to populate it.
The Adapter also knows about the connection to the data source. Figure 4 is a model
that shows the simple relationship between the Data Adapter and the data source.
Q2. Differentiate between Dataset and Datareader?

Ans. The main differences between Dataset and Datareader are as :

Data Reader Data Set

1. It’s a connection oriented, whenever 1. It is connectionless. Whenever you


you want to fetch the data from want to fetch data from database, It
database that you need the connection connects indirectly to the database
and after fetching the data connection and create a virtual database in local
is disconnected. system and then disconnected from
database.
2. It’s a Read only format, you can’t 2. Its easily read and write data from
update records. virtual database.

3. Datareader is used to retrieve data 3. Dataset is cache of records retrieve


from datasource. from data source.

4. Data cannot be transfer to datasource. 4. Data can be transfer to datasource.

5. It is Faster. 5. It is slower than dataset.

Q3. Write a Vb.Net program code to insert a TextBox value into Sql
database?

Ans: The code to insert a text box value into sql database is as:

Dim myConnection As SqlConnection


Dim myCommand As SqlCommand
Dim ra as Integer
'integer holds the number of records inserted
myConnection = New SqlConnection
("server=localhost;uid=sa;pwd=;database=Hospital")
'you need to provide password for sql server
myConnection.Open()
mycommand = New SqlCommand("INSERT INTO Patient
(ID,Name,address,DateofBirth,Gender,Phone,Emergencycontact,D
ateofRegistration) VALUES('" + lblid.Text + "','" +
txtname.Text + "','" + rtxtaddress.Text + "','" +
DateTimePicker1.Text + "','" + cmbgender.Text + "','" +
txtphone.Text + "','" + txtemcon.Text + "','" +
txtdoreg.Text + "')", mycon)ra=myCommand.ExecuteNonQuery()
MessageBox.Show("New Row Inserted" & ra)
myConnection.Close()
 

Q4. Briefly describe the crystal reports? Explain the mechanism to connect
crystal report using Vb.Net?
Ans: Crystal Reports are a business intelligence application used to design and generate
reports from a wide range of data sources. Several other applications, such as Microsoft
Visual Studio, bundle an OEM version of Crystal Reports as a general purpose reporting tool.
Crystal Reports became the de facto standard report writer when Microsoft released it with
Visual Studio.

Report designer

Crystal Reports allows users to graphically design data connections and report layout. In the
Database Expert, users can select and link tables from a wide variety of data sources,
including Microsoft Excel spreadsheets, Oracle databases, Business Objects Enterprise
business views, and local file system information

Supported data sources

Accessible data sources include the following:

 Databases such as PostgreSQL, Sybase, IBM DB2, Ingres, Microsoft Access,


Microsoft SQL Server, MySQL, Interbase and Oracle
 Btrieve
 Spreadsheets such as Microsoft Excel
 Text files
 HTML XML files
Development

Crystal Reports comes integrated with Visual Studio. Crystal Reports allows Java developers
to build applications with Crystal Reports components.

These Steps are used to connect crystal report using vb.net :


Click on Project menu
-->then Click Add New Item
-->Choose Crystal Report
-->Give the name of the report that you want to give
-->Click on Add Report
and also
-->Click Add New Dataset(.XSD File)
-->Right Click on That File Add Table Adapter
-->Make Connection and Write The Query and Follow The Step
as Come In Wizard
-->The In Blank Report Go Field Explore
-->DataBase Fields and Chose ADO.NET Dataset it The Table
you have Create in Dataset
-->Now Drag and Drop it in You Reports
 

Q5. Discuss the different ways to store and retrieve images in SQL server database
through Vb.Net?
Ans:
Function SaveImage _
   (ByVal FileName As String) As Integer
   ' Create a FileInfo instance
   ' to retrieve the files information
   Dim fi As New FileInfo(FileName)

   ' Open the Image file for Read


   Dim imgStream As Stream = _
      fi.OpenRead

   ' Create a Byte array the size


   ' of the image file for the Read
   ' methods buffer() byte array
   Dim imgData(imgStream.Length) As Byte
   imgStream.Read(imgData, 0, fi.Length)

   Dim cn As New SqlConnection _


      (ConfigurationSettings.AppSettings("cn"))
   Dim cmd As New SqlCommand("Images_ins", cn)
   cmd.CommandType = CommandType.StoredProcedure

   With cmd.Parameters
      .Add("@FileName", VarChar, 100).Value = _
         fi.Name
      .Add("@FileType", VarChar, 10).Value = +
         fi.Extension
      .Add("@Image", Image).Value = imgData
      .Add("@FileSize", Int, 4).Value = fi.Length
   End With

   cn.Open()
   cmd.ExecuteNonQuery()
   cn.Close()
   cn.Dispose()
End Function
The image field in SQL Server is simply a byte array. Here is the significant code you will
need. Let's assume the name of your image field in the database is "imageField". Hope this
helps.

To retrieve an image and save it to disk:

//dr is a DataReader returned from a SELECT command


Dim imageInBytes As Byte() = dr("imagefield")
Dim memoryStream As System.IO.MemoryStream = _
    New System.IO.MemoryStream(imageInBytes, False)
Dim image As System.Drawing.Image = _
    System.Drawing.Image.FromStream(memoryStream)
image.Save("c:\image")

To save an image into SQL Server from disk:

''Get the image file into a Byte Array


Dim image As Byte() = System.IO.File.ReadAllBytes("c:\image.jpg")
''Add the byte array as a parameter to your Insert/Update SQLCommand
parameters.Add("@ImageField", image)

Q6. Is it possible to send and retrieve XML files on server using HTTP protocol? If so,
brief the programmatic steps to send and retrieve XML files?
Ans:

You might also like