REAL TIME QUESTIONS

Methods of the Command Objects with databases?

The Command object is represented by two corresponding classes: SqlCommand and OleDbCommand. Command objects are used to execute statements (commands) to a database via a data connection. The Command objects can be used to execute stored procedures on the Database, SQL statements, or return complete tables directly. Command objects

Provide three methods that are used to execute commands on the database ?
  1. • ExecuteNonQuery. Executes direct SQL commands, such as INSERT, UPDATE or DELETE.
  2. • ExecuteScalar. Returns a single value from a Database Query.
  3. • ExecuteReader. Returns a result set by way of a DataReader object.
How do I insert data entered in a textbox into the database?

The data you enter in the textboxes will be inserted into the database when of the click of a Button.

The working senario is a database called "Emp" with a table named "Table1" with three columns. Also a Form with three TextBoxes and one Command Button.

How do I access SQL server in VB.NET?

To access data from a table in ?SQL Server you need to import the namespace System.Data.SqlClient and establish a connection from the application to the server.
The following code demonstrates how to connect to a ?SQL Server and display data from the "Discounts" table in the sample database "PUBS".

How to insert an image in Access Database?

The following code asks for a path of a Gif image. Then inserts the Gif image to an Access database.

File name is Image.vb

Imports System
Imports System.IO
Imports System.Data

Public Class SaveImage
Shared Sub main()

Dim o As System.IO.FileStream
Dim r As StreamReader
Dim gifFile As String

Console.Write("Enter a Valid .Gif file path")
gifFile = Console.ReadLine

If Dir(gifFile) = "" Then
Console.Write("Invalid File Path")
Exit Sub
End If

o = New FileStream(gifFile, FileMode.Open, FileAccess.Read, FileShare.Read)
r = New StreamReader(o)

Try

Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New _ System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data

Source=Test.mdb")

Dim Sql As String = "INSERT INTO Images (Pic,FileSize) VALUES (?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@Pic", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.Parameters.Add("@FileSize", System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length

Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Catch ex As Exception
Console.Write(ex.ToString)

End Try
End Sub
End Class

A file will be inserted in the Database each time the code is executed.

RELATED POST

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART THREE

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FOUR

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FIVE

ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE

ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO

You can also learn the concept of frame work concept in detail with questions and answers in the following place.

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART ONE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TWO

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART THREE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FOUR

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FIVE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SIX

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SEVEN

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART EIGHT

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART NINE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TEN

No comments:

Post a Comment