Saturday, December 26, 2009

To count number of individual character in given string

protected void Button2_Click(object sender, EventArgs e)
{
int j = 0;
string myString = TextBox1.Text;
char[] ch = myString.ToCharArray();
foreach (char a in ch)
{
if (a.ToString().Equals("a"))
{
j = j + 1;
}
}
TextBox1.Text = j.ToString();

}

Thursday, December 3, 2009

To get Date in Ms-Access using SQL Query Wizard

select * from table1 where doj> datevalue( "11/11/2009" )

Sunday, November 29, 2009

For and Foreach Statement Difference

string[] n = { "a", "b","c" };
foreach (string c in n)
{
string k = c;
}
for (int i = 0; i < n.Length; ++i)
{
string b = n[i];
}

Thursday, November 26, 2009

To Store and Retrieval Image in Windows Application

****************************************************************
Upload the Image in SqlServer2005

SqlConnection con = new SqlConnection("server=vivek\\server2005;initial catalog=TESTIMAGE;integrated security=true");
con.Open();
SqlCommand cmd = new SqlCommand("IMG_INSERT", con);
cmd.Parameters.AddWithValue("@id", textBox2.Text);
//////////////////////
MemoryStream stream = new MemoryStream();
pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic = stream.ToArray();
cmd.Parameters.AddWithValue("@img", pic);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
MessageBox.Show("Sucessfully Saved");


*************************************************************************
Download and Display in to Picture using Timer

//Global Declaration

private string s = ConfigurationSettings.AppSettings["conn"];
DataSet ds = new DataSet();
static int cnt = 0;

//Form Load Coding

private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(s);
con.Open();
SqlDataAdapter ada = new SqlDataAdapter("SELECT studid,PHOTO FROM studentregistration", con);
ada.Fill(ds);
}

//Timer Coding


private void timer1_Tick(object sender, EventArgs e)
{
Bitmap map ;
if (cnt < ds.Tables[0].Rows.Count)
{
byte[] bytes = (byte[])ds.Tables[0].Rows[cnt][1];
MemoryStream mem = new MemoryStream(bytes);
map = new Bitmap(mem);
pictureBox1.Image = map;
cnt += 1;

}
else
{
cnt = 0;
}
}

Monday, November 23, 2009

To add controls dynamically in Web Application

Steps:

i)To add ContentHolder control in Webpage

ii) Create an object for Label

Label l = new Label();
l.Text="Hai"

iii) PlaceHolder1.Controls.Add(l);

To Load All Country Names in DropDownList

private void PopulateCountryName(DropDownList dropDown)
{
Dictionary<string, string> objDic = new Dictionary<string, string>();

foreach (CultureInfo ObjCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{

RegionInfo objRegionInfo = new RegionInfo(ObjCultureInfo.Name);

if (!objDic.ContainsKey(objRegionInfo.EnglishName))
{
objDic.Add(objRegionInfo.EnglishName, objRegionInfo.TwoLetterISORegionName.ToLower());
}
}
List<KeyValuePair<string, string>> myList = new List<KeyValuePair<string, string>>(objDic);
myList.Sort(

delegate(KeyValuePair<string, string> firstPair,

KeyValuePair<string, string> nextPair)
{
return firstPair.Value.CompareTo(nextPair.Value);
}
);
foreach (KeyValuePair<string, string> val in myList)
{
dropDown.Items.Add(new ListItem(val.Key, val.Value));
}
}

Friday, November 20, 2009

SQL Queries

*****************************************************************

To Set column values as empty which contains zeros

SELECT (case when quantity = 0 then '' else quantity end) AS 'quantity'
FROM stock