Feeds:
Posts
Comments

Archive for February, 2006

case in sql(a nice sql query)

This is a nice sql query, I was afraid with a table and finally i got WITH CASE which helped me to implement confition in query. nice……..

SELECT CASE WHEN price IS NULL THEN ‘Not yet priced’ WHEN price = 10 and price THEN ‘Very Reasonable Title’ WHEN price >= 10 and price <= 20 THEN ‘Coffee Table Title’ ELSE ‘Expensive book!’ END AS “Price Category”, CONVERT(varchar(20), title) AS “Shortened Title” FROM pubs.dbo.titles ORDER BY price

Advertisements

Read Full Post »

using Calendar control in ASP.NET

 
This is a nice Calendar in ASP
<form name=”form1″ runat=server><asp:Label id=”Label1″ style=”Z-INDEX: 101;runat=”server”></asp:Label>

<asp:calendar id=”Calendar1″ runat=”server”

OnSelectionChanged=”Date_Selected” SelectWeekText=”week”

SelectMonthText=”month” SelectionMode=”DayWeekMonth”

NextPrevFormat=”ShortMonth” Font-Size=”12px”

Font-Name=”Verdana”>

<TodayDayStyle Font-Bold=”True” />

<DayHeaderStyle Font-Bold=”True” />

<OtherMonthDayStyle ForeColor=”gray” />

<TitleStyle BackColor=”#3366ff” ForeColor=”white” Font-Bold=”True” />

<SelectedDayStyle BackColor=”#ffcc66″ Font-Bold=”True” />

<NextPrevStyle ForeColor=”white” Font-Size=”10px” />

<SelectorStyle BackColor=”#99ccff” ForeColor=”navy” Font-Size=”9px” />

</asp:calendar>

</form>

 
After writing this in your .aspx page go to .aspx.cs page and write this
protected void Date_Selected(object sender, EventArgs e)      {

      switch (Calendar1.SelectedDates.Count)

      {

      case (0): //None

      {

        Label1.Text = “No dates are currently selected”;

        break;

      }

      case (1): //Day

      {

        Label1.Text = “The selected date is ” +

        Calendar1.SelectedDate.ToShortDateString();

        break;

      }

      case (7): //Week

      {

        Label1.Text = “The selection is a week beginning ” +

        Calendar1.SelectedDate.ToShortDateString();

        break;

      }

      default: //Month

        Label1.Text = “The selection is a month beginning ” +

        Calendar1.SelectedDate.ToShortDateString();

        break;

      }

    }

Read Full Post »

read rss feed using c#

I read a rss from web site. Here the example
 
DataSet ds = new DataSet();
ds.ReadXml
(http://newsrss.bbc.co.uk/rss/ newsonline_world_edition/front_page/rss.xml, XmlReadMode.Auto);
DataGrid1.DataSource=ds.Tables[“item”];
DataGrid1.DataBind();
 
Label1.Text=ds.Tables[3].Rows[5][1].ToString(); //read from a dataset and get a cell

Read Full Post »

important in query

Some time we want not to get null values returning from our query and to protect this need to use ISNULL. hrre is an example fo using ISNULL.
ISNULL((SELECT name FROM employee WHERE id = employeeSalary.eID), ”)
 
Name of the employee id returnig from this query but if name is null it return a space.
 
 
Sometime we need to cast a field here is an example of casting value
(SELECT RTrim(CAST(day AS char(3))) + ‘-‘ + RTrim(CAST(month AS char(3))) + ‘-‘ + RTrim(CAST(year AS char(3))) FROM employee AS date
 
it cast and concate day month and year

Read Full Post »

connection between SQL Server and C#.net

Hi, This is an easy thing which i have done, i establish connection between SQL Server and C#.net there is a table in my database named login. My code take name and password from textbox and and password field and then check with the databse if name and passwword is correct then redirenc to a new page.
Here is the sample code:
  string connectionString = “Data Source=(local);Initial Catalog=ashraftest;user id=sa;password=faisal”;
  string mySelectQuery = “SELECT * from login;”;
  SqlConnection myConnection = new SqlConnection(connectionString);
  SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
  myConnection.Open();
  SqlDataReader myReader;
  myReader = myCommand.ExecuteReader();
  string s1= TextBox1.Text;
  string s2= Password1.Value;
  while (myReader.Read())
  {
  if((s1.Equals(myReader.GetString(0))) &&
        (s2.Equals(myReader.GetString(1))))
  Response.Redirect(“loginpage.aspx?name=”+s1);
  }
  myReader.Close();
  myConnection.Close();

Read Full Post »

use bangla font in java

i tried to write bangla font in a text field and have dane this successfully. Here is the source code of using bangla font in java.

     File fontFile = new File(“Boishkhi.ttf”);
     FileInputStream inStream = new FileInputStream(fontFile);
     Font banglaFont =Font.createFont(Font.TRUETYPE_FONT,inStream);
     banglaFont =banglaFont.deriveFont(Font.PLAIN,12);
     textField.setFont(banglaFont);

Here i am using Boisgakhi.tff as an example you can use any font just change font name.

Read Full Post »

read doc file from c#

I have read a word file successfully using c#.net and printing this file on a rich text editor.here is the souce code

Word.Application app=new Word.ApplicationClass();
object nullobj=System.Reflection.Missing.Value;
object file = @”C:test.doc”;
Word.Document doc = app.Documents.Open
 ( ref file, ref nullobj, ref nullobj, ref nullobj,
 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
 ref nullobj, ref nullobj, ref nullobj, ref nullobj,
 ref nullobj, ref nullobj, ref nullobj,ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
string text = data.GetData(DataFormats.Text).ToString();
richTextBox1.Text=text;Console.WriteLine(text);
doc.Close(ref nullobj, ref nullobj, ref nullobj);
app.Quit(ref nullobj, ref nullobj, ref nullobj);

Read Full Post »