Friday, July 10, 2009

Image Store in Database (BLOB)

There is two process of image store in web application..
1. physicaly store
2. Store in Database (Blob)
I give the code of store image in database..

//when the image has a valid path
if(imgname!="")
{
FileStream fs;
fs=new FileStream(@imgname,FileMode.Open,FileAccess.Read);
//a array of byte to read the image
byte[] blobimg = new byte[fs.Length];
fs.Read(blobimg,0,System.Convert.ToInt32(fs.Length));
fs.Close();
// open database and excute below query...
// emp is a table name where three column is id (nvarchar), name(nvarchar) and photo(img)
query="insert into emp(id,name,photo) values(" + txtid.Text + "," + "'" + txtname.Text + "'," + " :BlobParameter )";
OracleParameter blobParameter = new OracleParameter();
blobParameter.OracleType = OracleType.Blob;
blobParameter.ParameterName = "BlobParameter";
blobParameter.Value = blobimg;
cmnd=new OracleCommand(query,conn);
cmnd.Parameters.Add(blobParameter);
cmnd.ExecuteNonQuery();
MessageBox.Show("Succesfully done!");
}

Read img from database
There is use following contros:

1. combobox:cmbname
2. label:lblname
3. buttons:btnshow
4. picturebox:img
global declare these variable:
OracleConnection con;
OracleDataAdapter empadp;
DataSet ds;
string constr;
//bind name of img in combobox at page load event
constr="User Id=sc;Password=t;Data Source=st;";con=new OracleConnection(connstr);
con.Open();
empadp=new OracleDataAdapter();
empadp.SelectCommand=new OracleCommand("SELECT * FROM emp",conn);
ds=new DataSet("dset");
empadp.Fill(ds);
DataTable dt;
dt=ds.Tables[0];
cmbname.Items.Clear();
foreach(DataRow dr in dt.Rows)
{
cmbname.Items.Add(dr[1].ToString());
cmbname.SelectedIndex=0;
}

// show img when select name of img from combobox,
DataTable dt = ds.Tables[0];
//if there is an already an image in picturebox, then delete it
if(img.Image != null)
{
img.Image.Dispose();
}
//using filestream object write the column as bytes and store it as an image
FileStream FS = new FileStream("image.jpg", FileMode.Create);
foreach(DataRow dr in dt.Rows)
{
if(dr[1].ToString() == cmbname.SelectedItem.ToString()) //check name of the image
{
byte[] blob = (byte[])dr[2];
FS.Write(blob,0,blob.Length);
FS.Close();
FS = null;
img.Image = Image.FromFile("image.jpg");
img.SizeMode = PictureBoxSizeMode.StretchImage;
img.Refresh();
}
}
Thanks and Regards
Varun Bansal
Assistant Programmer
NIC, Jaipur

Friday, July 3, 2009

Validate float value while entering in textbox using javasript

on .aspx page
<script language="javascript" type="text/javascript"7gt;
function check_float(e,field)
{
if (!(((e.keyCode>=48)&&(e.keyCode<=57))(e.keyCode==46)))
{
alert("Only Digits Are Allowed!");
e.keyCode=0;
}
if (e.keyCode==46)
{
var patt1=new RegExp("\\.");
var ch =patt1.exec(field);
if(ch==".")
{
alert("More then one decimal point not allowed");
e.keyCode=0; }
}
}
</script>

on code behind (.aspx.cs page) :
TextBox5.Attributes.Add("onkeypress", "check_float(event,document.getElementById('" + TextBox5.ClientID + "').value)");
TextBox6.Attributes.Add("onkeypress", "check_float(event,document.getElementById('" + TextBox6.ClientID + "').value)");

Thanks and Regards
Varun Bansal
Assistant Programmer
NIC, Jaipur

Tips & Tricks : Nero 8

Nero BurnRights
Nero 8 that allows you to define user authentication for specific user on your system can burn CDs and DVDs. Go to Start > All Programs > Nero 8 > Nero Toolkit > Nero BurnRights. Select the type of users that you want to give permission to, and click OK.

Do Not Eject The CD/DVD

Every CD immediately ejected after burn from the drive by default. To keep the CD or DVD in the drive once it’s done, go to File > Options > Expert Features. Check the box "Do not eject the disc after the burn is complete" and click OK.

Thanks and Regards
Varun Bansal
Assistant Programmer
NIC, Jaipur

Portable your mobile numbers within a week, start with digit of '8'

The Telecom Regulatory Authority of India (TRAI) provide the mobile number portability (MNP), which lets users change mobile carriers while keeping the same phone number. (Exp. if you have mobile number 912345**** with xyz company, after then MNP you can change service provider with privious same number.).

The addition of the ‘8’ prefix would give 10 crore new numbers to the DoT to play with; and which also means a lot of moolah to auction off special numbers!

Thanks and Regards
Varun Bansal
Assistant Programmer
NIC, Jaipur

Thursday, July 2, 2009

Tips & Tricks: Google Chrome

Google Chrome is an extremely fast and lightweight browser. The top bar and the menu bar have been omitted and giving a large space for browsing. There is many feature in Google Chrome..

Inspect Memory Usage
Google Chrome has advanced options for memory usage. Right-click on the browser tab and select ‘Task Manager’. If you will open four tab then you will get a window showing how much memory is being used by each tab in the browser.
Now click on ‘Stats for Nerds’ and a new tab will open in the same browser, with information of a process ID, name of the site, memory and virtual memory usage. The great thing about this feature is that if you are using other browsers at the same time, then the tab shows the memory usage by that browser as well.

Bookmarks
For bookmark, Click on the star icon befor the address bar. it show the list of bookmarks. You can use this using shortcut key [ctrl] + [b]

Navigation Tips
Drag and drop any tab from the existing browser into the desktop to start a new browser . Your can open new tab using by shortcut key [Ctrl] + [Shift] + [T]. Use [Ctrl] + [1] to [9] to cycle through tabs from the keyboard.

Thanks and Regards
Varun Bansal
Assistant Programmer
NIC, Jaipur

Wednesday, July 1, 2009

Add text box in gridview at runtime

hi,you can add the row with text box dynamically on runtime with the click of button using this codesuppose that u have one grid view with three column and one button like that:
1. rownumber
2. first name
3. middle name
4. last name

on page load event.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetdefaultRow ();
// set the default gridview
}
}

private void SetdefaultRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("first name", typeof(string)));
dt.Columns.Add(new DataColumn("middle name", typeof(string)));
dt.Columns.Add(new DataColumn("last name", typeof(string)));
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["first name"] = string.Empty;
dr["middle name"] = string.Empty;
dr["last name"] = string.Empty;
dt.Rows.Add(dr);
//dr = dt.NewRow();
//Store the DataTable in ViewStateViewState["Table"] = dt;
Gridviewemp.DataSource = dt;
Gridviewemp.DataBind();
}

on button click:

protected void ButtonAdd_Click(object sender, EventArgs e)
{
AddNewRow();
// add new row with three textbox in gridview
}

private void AddNewRow()
{
int rowIndex =0;
if (ViewState["Table"] != null)
{
DataTable dtTable = (DataTable)ViewState["Table"];
DataRow drCurrentRow = null;
if (dtTable.Rows.Count > 0)
{
for (int i = 1; i <= dtTable.Rows.Count; i++)
{
//extract the TextBox values
TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = i + 1;
drCurrentRow["first name"] = box1.Text;
drCurrentRow["middle name"] = box2.Text;
drCurrentRow["last name"] = box3.Text;
rowIndex++;
}
//add new row to DataTable
dtCurrentTable.Rows.Add(drCurrentRow);
//Store the current data to ViewState
ViewState["Table"] = dtTable;
//Rebind the Grid with the current data
Gridviewemp.DataSource = dtTable;
Gridviewemp.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
}

Thanks and Regards
Varun Bansal
Assistant Programmer
NIC, Jaipur