Set - 9

Question 26 :

How do you get records number from 5 to 15 in a dataset of 100 records? Write code. 

Answer :

Answer1

DataSet ds1=new DataSet(); String strCon="data source=IBM-6BC8A0DACEF;initial catalog=pubs;integrated security=SSPI;persist" +" security info=False;user 
id=sa;workstation id=IBM-6BC8A0DACEF;packet size=4096?;

String strCom1="SELECT * FROM employee";
SqlDataAdapter sqlDa1=new SqlDataAdapter(strCom1,strCon);
ds1.Tables.Add("employee");
sqlDa1.Fill(ds1,40,50,ds1.Tables["employee"].TableName);
DataGrid dg1.DataSource=ds1.Tables["employee"].DefaultView;
dg1.DataBind();

Answer2

OleDbConnection1.Open()
OleDbDataAdapter1.Fill(DataSet21, 5, 15, "tab")

This will fill the dataset with the records starting at 5 to 15


Question 27 :

How do you call and execute a Stored Procedure in .NET? Give an example. 

Answer :

Answer1

ds1=new DataSet();

sqlCon1=new SqlConnection(connectionstring);

String strCom1="byroyalty";

sqlCom1=new SqlCommand(strCom1,sqlCon1);
sqlCom1.CommandType=CommandType.StoredProcedure;
sqlDa1=new SqlDataAdapter(sqlCom1);
SqlParameter myPar=new SqlParameter("@percentage",SqlDbType.Int);
sqlCom1.Parameters.Add (myPar);
myPar.Value=40;
sqlDa1.Fill(ds1);
dg1.DataSource=ds1;
dg1.DataBind(); 

Answer2

Yes

Dim cn as new OleDbConnection ( "Provider=Microsoft.Jet.OLEDB.4.0;"+ _
"Data Source=C:\Documents and Settings\User\My Documents\Visual Studio Projects\1209\db1.mdb"+ _
"User ID=Admin;"+ _
"Password=;");
Dim cmd As New OleDbCommand("Products", cn)
cmd.CommandType = CommandType.StoredProcedure

Dim da As New OleDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "Products")
DataGrid1.DataSource = ds.Tables("Products") 


Question 28 :

How do u call and execute a stored procedure in .NET? 

Answer :

system.Data;
system.Data.SqlClient;

SqlConnection sqCon = new SqlConnection("connection string");
SqlCommand sqCmd = new SqCmd();
sqCmd.Connection = sqCon;
sqCmd.CommandText = procedure_name;
sqCmd.CommandType = CommandType.StoredProcedure;
sqComd.ExecuteReader();


Question 29 :

How do you create thread in .NET?

Answer :

1) Import System.Threading
2) Create a new thread using new Thread() and assign the address of the method
3) Use Thread.Start method to start the execution

using System;
using System.Threading;
public class Test{
	static void Main(){
		ThreadStart job = new ThreadStart(ThreadJob);
		Thread thread = new Thread(job);
		thread.Start();
		....
	}
}


Question 30 :

What is the output for the following code snippet:

public class testClass{
	public static void Main(string[] args){
		System.Console.WriteLine(args[1]);
	}//end Main
}//end class testClass

* Compiler Error
* Runtime Error
* Hello C# world
* None of the above

Answer :

Runtime Error