string str = "";
str = textBox1.Text;
//Take a substring whose length is 101...
string Tempstr = str.Substring(0, 101);
//Take 101th character....
string Mystr = str.Substring(101, 1);
//Check whether 101th character is space....
//If it is a space, then word is not splitted....
if (Mystr != " ")
{
//Check each character from 101th position..
for (int i = 102; ; i++)
{
string myS = str.Substring(i, 1);
if (myS == " ")
{
string s = str.Substring(0, i);
label1.Text = s;
break;
}
}
}
else
{
label1.Text = Tempstr;
}
2) How do you send mail. Write a piece of code?
using System.Web.Mail;
MailMessage message = new MailMessage();
message.From = ;
message.To = ;
message.Subject= "Subject of the Message";
message.Body = "Body Text";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(message);
3) What is the difference between Cache and application variable?
4) How do you return two tables in a StoredProcedure?
/* Test stored procedure. Returns 2 ResultSets */
CREATE PROCEDURE Sp_GetMultiTables
AS
BEGIN
SELECT CategoryName FROM Categories ORDER BY CategoryName
SELECT LastName FROM Employees ORDER BY LastName
END
GO
SqlConnection Con = new SqlConnection("server=SvrName;database=DbName;user id=sa;password=xxx");
SqlCommand Cmd = new SqlCommand();
Con.Open();
Cmd.Connection = Con;
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.CommandText = "Sp_GetMultiTables";
//SqlDataReader dr = Cmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView2.DataSource = ds.Tables[1];
Con.Close();
5) Suppose you have given in command object a query which return two tables. How do you show two tables using datareader?
SqlConnection Con = new SqlConnection("server=NameOfServer;database=DBname;user id=sa;password=xxx");
SqlCommand Cmd = new SqlCommand();
Con.Open();
Cmd.Connection = Con;
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.CommandText = "Sp_GetMultiTables";//This Sp returns two tables...
SqlDataReader dr = Cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
do
{
while (dr.Read())
{
for (int i = 0; i < dr.FieldCount; i++)
{
string nameOfColumn = dr.GetName(i);
Response.Write(string.Format("{0} : {1} ", nameOfColumn, dr.GetValue(dr.GetOrdinal(nameOfColumn)).ToString()) + "
");
");
}
}
Response.Write("
");
");
}
while (dr.NextResult());
Con.Close();
6) Difference between dataset and datareader?
7) Suppose I placed a dataset in a Cache. If database is updated in the meantime, how do you make Cache to hold new content.
SqlCacheDependency using ASP.NET 2.0 and SQL Server 2005 is a beautiful thing :) Although getting SqlCacheDependency to work with SQL Server 2000 is not rocket science, there are a few extra moving parts that need to be set-up in your web.config and on SQL Server 2000. When using SQL Server 2005, all of that goes away :)
Enable Service Broker
Before SqlCacheDependency will work with SQL Server 2005, you first have to enable Service Broker, which is reponsible for the notification services that let the web cache know a change has been made to the underlying database and that the item in the cache must be removed.
ALTER DATABASE MyCustDB SET ENABLE_BROKER;
ALTER DATABASE MyCustDB SET ENABLE_BROKER;
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.