Here is the code for read the registry value using C#.
First I’m creating registry key value and string value in local machine as follows,
myKey –> key value
myValue –> string name
myReturnValue –> string value
Code for Registry value Reading using C#…
using Microsoft.Win32;
try
{
RegistryKey registry = Registry.LocalMachine.CreateSubKey(”SOFTWARE\\myKey”);
if (registry != null)
{
MessageBox.Show(registry.GetValue(”myValue”));
registry.Close();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString());
}
Code for Values writing in Registry using [...]
Filed under: C# Code, Programming Logic by Rishav
No Comments »
SQL injection is a technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is in fact an instance [...]
Filed under: ASP.NET, C# Code, SQL Server Help by Rishav
1 Comment »
Boxing and unboxing is a essential concept in C# type system. With Boxing and unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. Boxing and unboxing enables a unified view of the type system wherein a value of any type can [...]
Filed under: C# Code, Definition of Terms by Rishav
No Comments »
To store an image in to sql server using C#, you need to read image file into a byte array. Once you have image data in byte array, you can easity store this image data in sql server using sql parameters. Following code explains you how to do this.
private void cmdSave_Click(object sender, EventArgs e)
{
try
{
//Read Image [...]
Filed under: C# Code, SQL Server Help by Rishav
No Comments »
Use the code below to retrieve data from EXCEL sheet in C#
An openfiledialog box control has been usedd to get the excel file.
excel.sheetname gives the name of the sheet in the excel file.
exceldetail.col and exceldetail.col1 have been use for column in excel sheet.
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string ConnectionString = @”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + openFileDialog1.FileName.ToString() + “;Extended Properties=\”Excel [...]
Filed under: C# Code by Rishav
No Comments »
Code for Retrieving Values from Access Database
try
{
OleDbConnection thisConnection = new OleDbConnection(@”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Hash-Tech\Hash Reminder Setup\Hash Reminder.mdb”);
thisConnection.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(”Select * from ReminderTable”, thisConnection);
OleDbCommandBuilder cmd = new OleDbCommandBuilder(adp);
DataSet ds = new DataSet(”ReminderTable”);
adp.Fill(ds, “ReminderTable”);
DataRow dr = ds.Tables["ReminderTable"].NewRow();
dr["SetDate"] = setdateinp;
dr["SetTime"] = settimeinp;
dr["ReminderType"] = remtypeinp;
dr["ReminderHead"] = remheadinp;
dr["ReminderText"] = remtextinp;
dr["EndDate"] = enddateinp;
dr["EndTime"] = endtimeinp;
dr["Status"] = “Progress”;
ds.Tables["ReminderTable"].Rows.Add(dr);
adp.Update(ds, “ReminderTable”);
thisConnection.Close();
}
catch (Exception z)
{
MessageBox.Show(”Error” [...]
Filed under: C# Code by Rishav
No Comments »
The Code Written below Makes a Page that allows user to upload file to the Server.
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=”server”>
protected void UploadButton_Click(object sender, EventArgs e)
{// Specify the path on the server to save the uploaded file to.
String savePath = Server.MapPath(”~/UploadedFiles”);
// Before attempting to perform operations [...]
Filed under: ASP.NET, C# Code, Programming Logic by Rishav
No Comments »
The CSV files are files containing the values seperated by comma. These files are generally used to store contact Details becuase they are very much acceptable across different mail client and websites. Here i am writing code to craete a CSV file from the Data containe in the Datagrid View.
DatagridView Name = dataGridView1
File Created at [...]
Filed under: C# Code, Programming Logic by Rishav
No Comments »
Many of you have had develope applications that use the database for a proper functioning, the main problem comes when you consider to eploy you application at any other machine. The Database is not available at the machine, so your application gives error. To remove this error, there are two ways you create the database [...]
Filed under: C# Code, Programming Logic, SQL Server Help by Rishav
3 Comments »
Bored by using the same Rectangular Button Control from your toolbox. Us the method mentioned below to create a new control named CircularButton in your toolbox and use it in your Form. Just follow the steps below carefully.
Step 1 – Open your Windows Application or a new Window Application in Visual Studio 2005.
Step 2 – [...]
Filed under: C# Code, Programming Logic by Rishav
No Comments »