26.02.2015 Views

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

First below is the code , after the code i have given the explanation for it.For this sample<br />

we will also need a SQL Table setup which i have imported using the DTS wizard.<br />

Private Sub LoadData()<br />

‘ note :- with and end with makes your code more readable<br />

Dim strConnectionString As String<br />

Dim objConnection As New SqlConnection<br />

Dim objCommand As New SqlCommand<br />

Dim objReader As SqlDataReader<br />

Try<br />

‘ this gets the connectionstring from the app.config<br />

file.<br />

‘ note if this gives error see where the MDB file is<br />

stored in your pc and point to that<br />

strConnectionString =<br />

AppSettings.Item(“ConnectionString”)<br />

‘ take the connectiostring and initialize the connection<br />

object<br />

With objConnection<br />

.ConnectionString = strConnectionString<br />

.Open()<br />

End With<br />

objCommand = New SqlCommand(“Select FirstName from<br />

Employees”)<br />

With objCommand<br />

.Connection = objConnection<br />

objReader = .ExecuteReader()<br />

End With<br />

‘ looping through the reader to fill the list box<br />

Do While objReader.Read()<br />

lstData.Items.Add(objReader.Item(“FirstName”))<br />

Loop<br />

Catch ex As Exception<br />

Throw ex<br />

Finally<br />

objConnection.Close()<br />

End Try<br />

<br />

<br />

<br />

* What are your negative points ? (Careful guy’s)<br />

179

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!