amit kumar


{ City } noida
< Country > india
* Profession * technical lead
User No # 67535
Total Questions Posted # 0
Total Answers Posted # 5

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 91
Users Marked my Answers as Wrong # 12
Questions / { amit kumar }
Questions Answers Category Views Company eMail




Answers / { amit kumar }

Question { Unique Software Systems, 15090 }

How to store image file in Sql server database?


Answer

//use this code to store image file in sql server database

//get directory Path(C:\\Temp) where image has stored and
use these two method in ur program

private void GetImagePath(string strDirectoryPath)
{
DirectoryInfo mobjDirInfo = new DirectoryInfo
(strDirectoryPath);
//object[] mobjStore = new object
[Directory.GetFiles(strDirectoryPath, "*.JPG").Length];
int counter =1;
foreach (FileInfo fl in mobjDirInfo.GetFiles
("*.JPG"))
{
// Create a new stream to load this photo
into
FileStream stream = new FileStream
(fl.FullName.ToString(), FileMode.Open, FileAccess.Read);

// Create a buffer to hold the stream bytes
byte[] buffer = new byte[stream.Length];

// Read the bytes from this stream
stream.Read(buffer, 0, (int)stream.Length);

// Now we can close the stream
stream.Close();

// Extract out the name of the file an use
it for the name of the photo
string strName =
Path.GetFileNameWithoutExtension(fl.Name.ToString());

// Insert the image into the database and
add it to the tree
InsertImageIntoDatabase(ref buffer,
strName, counter);
buffer = null;
counter = counter+1;
}
}


//Insert Images into sql server (create table TBLIMAGE
(PHOTOID int,PHOTONAME varchar(20),PHOTO IMAGE))
private void InsertImageIntoDatabase(ref byte[]
buffer, string strPhotoName, int intPhotoid)
{
if (mobjConn.State == ConnectionState.Closed)
{
mobjConn.Open();
}

mobjCmd = new SqlCommand("Insert Into TBLIMAGE
values(@PHOTOID,@PHOTONAME,@PHOTO)", mobjConn);
mobjCmd.Parameters.Add("@PHOTOID", intPhotoid);
mobjCmd.Parameters.Add
("@PHOTONAME",strPhotoName);
mobjCmd.Parameters.Add("@PHOTO", buffer);
mobjCmd.ExecuteNonQuery();

}

//if u have any query please revert back

Is This Answer Correct ?    9 Yes 1 No

Question { Wipro, 48975 }

can we assign null value to value type in c#?


Answer

//Use this
int? intNull = null;

Is This Answer Correct ?    64 Yes 10 No


Question { Kanbay, 9377 }

will this code works fine? or will it gives error?

Object obj=5;
int i=6;
i=i+obj;


Answer

//can not applied this because i is value type and obj is
reference type so this will create error
//u can do this
Object obj = 5;
int i = 6;
i = i + Convert.ToInt32(obj);

Is This Answer Correct ?    8 Yes 1 No

Question { Honeywell, 8059 }

If we want to construct our own Garbage collector what are
the steps things we have to do?


Answer

//Use this
System.GC.Collect();
System.GC.WaitForPendingFinalizers();

Is This Answer Correct ?    8 Yes 0 No

Question { 6114 }

how to change a value of particular cell in a data grid


Answer

private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
//Edit cell value
this.dataGridView1[e.ColumnIndex,
e.RowIndex].Value="Any Thing";

//find column name of cell
string strCulumnName = dataGridView1
[e.ColumnIndex, e.RowIndex].OwningColumn.Name;
}

Is This Answer Correct ?    2 Yes 0 No