sample text
December 14, 2015
December 5, 2015
Connection String in ASP.net
Opening the connection
private string ConStr;
ConStr = System.Configuration.ConfigurationManager.AppSettings["con"];
SqlConnection cnn = new SqlConnection(ConStr);
cnn.Open();
December 3, 2015
Background image to ASP.net Button
OnClick="btnDownload_Click" Height="95px" Width="90px"/>
December 2, 2015
The name 'HttpContext' does not exist in the current context
Add System.Web.dll by right clicking to your solution explorer -> Add reference
November 9, 2015
How to set column header text for specific column in Datagridview C#
this.dataGridView1.Columns["your database column name"].HeaderText = " preferred name";
November 4, 2015
October 17, 2015
Replace a Image
Write the following code with in the .class
display: block;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: url(images/newbanner.png) no-repeat;
width: 180px; /* Width of new image */
height: 236px; /* Height of new image */
padding-left: 180px; /* Equal to width of new image */
example
@media only screen and (max-width: 1036px) {
.logo-holder {
display: block;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: url(../images/logomob.jpg) no-repeat;
width: 180px; /* Width of new image */
height: 236px; /* Height of new image */
padding-left: 180px; /* Equal to width of new image */
top:0;
}
}
October 16, 2015
Double Pointers in C Language
#include<stdio.h> int main() { int num = 45 , *ptr , **ptr2ptr ; ptr = # ptr2ptr = &ptr; printf("%d",**ptr2ptr); return(0); }
Output
45
October 15, 2015
September 24, 2015
How to make a TextBox accept only alphabetic characters?
private void txtname_TextChanged(object sender, EventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(txtname.Text, "^[a-zA-Z]"))
{
MessageBox.Show("This textbox accepts only alphabetical characters");
txtname.Text = "";
}
}
{
if (!System.Text.RegularExpressions.Regex.IsMatch(txtname.Text, "^[a-zA-Z]"))
{
MessageBox.Show("This textbox accepts only alphabetical characters");
txtname.Text = "";
}
}
September 22, 2015
How to make a TextBox accept only Numeric values ?
private void txtEmpCode_TextChanged_1(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(txtEmpCode.Text, "[^0-9]"))
{
MessageBox.Show("Please enter only numbers.");
txtEmpCode.Text.Remove(txtEmpCode.Text.Length - 1);
txtEmpCode.Text = "";
}
}
{
if (System.Text.RegularExpressions.Regex.IsMatch(txtEmpCode.Text, "[^0-9]"))
{
MessageBox.Show("Please enter only numbers.");
txtEmpCode.Text.Remove(txtEmpCode.Text.Length - 1);
txtEmpCode.Text = "";
}
}
September 15, 2015
How to upload image to database in C#.net Windows Application
To Upload
SqlConnection cn= new SqlConnection(connectionString);
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpeg;*.bmp;*.png;*.jpg)|*.jpeg;*.bmp;*.png;*.jpg";
if (open.ShowDialog() == DialogResult.OK)
{
textBoximage.Text = open.FileName;
}
cn.Open();
string image = textBoximage.Text;
Bitmap bmp = new Bitmap(image);
FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read);
byte[] bimage = new byte[fs.Length];
fs.Read(bimage, 0, Convert.ToInt32(fs.Length));
fs.Close();
SqlCommand cmd = new SqlCommand("insert into TableName(imgdata) values(@imgdata)",cn);
cmd.Parameters.AddWithValue("@imgdata",SqlDbType.Image).Value=bimage;
cmd.ExecuteNonQuery();
cn.Close();
}
To Retrieve
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(new SqlCommand("Select Picture From TableName where FieldName=condition ", cn));
DataSet ds = new DataSet();
da.Fill(ds);
byte[] myImage = new byte[0];
myImage = (byte[])ds.Tables[0].Rows[0]["Picture"];
MemoryStream stream = new MemoryStream(myImage);
pictureBox1.Image = Image.FromStream(stream);
cn.Close();
SqlConnection cn= new SqlConnection(connectionString);
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpeg;*.bmp;*.png;*.jpg)|*.jpeg;*.bmp;*.png;*.jpg";
if (open.ShowDialog() == DialogResult.OK)
{
textBoximage.Text = open.FileName;
}
cn.Open();
string image = textBoximage.Text;
Bitmap bmp = new Bitmap(image);
FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read);
byte[] bimage = new byte[fs.Length];
fs.Read(bimage, 0, Convert.ToInt32(fs.Length));
fs.Close();
SqlCommand cmd = new SqlCommand("insert into TableName(imgdata) values(@imgdata)",cn);
cmd.Parameters.AddWithValue("@imgdata",SqlDbType.Image).Value=bimage;
cmd.ExecuteNonQuery();
cn.Close();
}
To Retrieve
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(new SqlCommand("Select Picture From TableName where FieldName=condition ", cn));
DataSet ds = new DataSet();
da.Fill(ds);
byte[] myImage = new byte[0];
myImage = (byte[])ds.Tables[0].Rows[0]["Picture"];
MemoryStream stream = new MemoryStream(myImage);
pictureBox1.Image = Image.FromStream(stream);
cn.Close();
September 8, 2015
Customize MessageBox in C#
MessageBox.Show("your message", "window title", MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
September 2, 2015
Open a form using short cut in C sharp
if (e.Alt && e.KeyCode == Keys.c)
{
ChangePassword f3 = new ChangePassword();
f3.ShowDialog();
}
and
set the KeyPreview=True
{
ChangePassword f3 = new ChangePassword();
f3.ShowDialog();
}
and
set the KeyPreview=True
August 11, 2015
How to write email when asked for sending.
Sometimes when you are asked to send a main to hr
Respected Sir/Mam,
In
response to your job notification for the various positions mentioned on your
website. I am attaching my resume.
Kindly get the attachment.
Regards,
Sudhir Singh
August 10, 2015
C# DataGridView Hide Columns and Rows
dataGridView1.Columns[1].Visible = false; dataGridView1.Rows[1].Visible = false;
August 4, 2015
July 26, 2015
June 22, 2015
June 21, 2015
June 17, 2015
Upload Excel Sheet data to Sql Server in Asp.net
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string sPath = Server.MapPath("~/BulkFolder/" + FileUpload1.FileName);
FileUpload1.SaveAs(sPath);
ImporttoSQL(sPath);
}
}
private void ImporttoSQL(string sPath)
{
try
{
string sSourceConstr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", sPath);
string sDestConstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
using (sSourceConnection)
{
string sql = string.Format("Select [Sno],[Subject],[Question],[op1],[op2],[op3],[op4],[Answer] FROM [{0}]", "Sheet1$");
OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
sSourceConnection.Open();
using (OleDbDataReader dr = command.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sDestConstr))
{
bulkCopy.DestinationTableName = "Questions";
bulkCopy.WriteToServer(dr);
Label1.Visible = true;
}
}
}
}
catch (Exception y)
{
Label1.Visible = true;
Label2.Visible = true;
Label3.Visible = true;
Label1.Text = "Cannot upload the quetions. Please check that";
Label2.Text = "1. All the values are present. No column is missing.";
Label3.Text = "2. Answer is in the numeric value or file format is wrong.";
}
}
Html Code
Untitled Page
Output
{
if (FileUpload1.HasFile)
{
string sPath = Server.MapPath("~/BulkFolder/" + FileUpload1.FileName);
FileUpload1.SaveAs(sPath);
ImporttoSQL(sPath);
}
}
private void ImporttoSQL(string sPath)
{
try
{
string sSourceConstr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", sPath);
string sDestConstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
using (sSourceConnection)
{
string sql = string.Format("Select [Sno],[Subject],[Question],[op1],[op2],[op3],[op4],[Answer] FROM [{0}]", "Sheet1$");
OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
sSourceConnection.Open();
using (OleDbDataReader dr = command.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sDestConstr))
{
bulkCopy.DestinationTableName = "Questions";
bulkCopy.WriteToServer(dr);
Label1.Visible = true;
}
}
}
}
catch (Exception y)
{
Label1.Visible = true;
Label2.Visible = true;
Label3.Visible = true;
Label1.Text = "Cannot upload the quetions. Please check that";
Label2.Text = "1. All the values are present. No column is missing.";
Label3.Text = "2. Answer is in the numeric value or file format is wrong.";
}
}
Html Code
Output
June 2, 2015
Student Registration in Android
A simple Student Registration with SQLite
Here we are going to create a simple Student registration Android Application using SQLite database.
Here is the output which we will achieve at the end.
MainActivity.java
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
EditText Rollno,Name,Course;
Button Add,Deletee,Update,View,ViewAll;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Rollno=(EditText)findViewById(R.id.Rollno);
Name=(EditText)findViewById(R.id.Name);
Course=(EditText)findViewById(R.id.course);
Add=(Button)findViewById(R.id.Add);
Deletee=(Button)findViewById(R.id.Deletee);
Update=(Button)findViewById(R.id.update);
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Add.setOnClickListener(this);
Deletee.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
ViewAll.setOnClickListener(this);
db=openOrCreateDatabase("mydatabase", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS mystudents(rollno VARCHAR,name VARCHAR,Course VARCHAR);");
}
@Override
public void onClick(android.view.View arg0) {
if(arg0==Add)
{
if(Rollno.getText().toString().length()==0)
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter Roll Number", Toast.LENGTH_SHORT);
t.show();
}
else if(Name.getText().toString().length()==0)
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter Name", Toast.LENGTH_SHORT);
t.show();
}
else if(Course.getText().toString().length()==0)
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter Course", Toast.LENGTH_SHORT);
t.show();
}
else
{
db.execSQL("INSERT INTO mystudents VALUES('"+Rollno.getText()+"','"+Name.getText()+
"','"+Course.getText()+"');");
Toast t = Toast.makeText(getApplicationContext(), "Added Sucessfully", Toast.LENGTH_SHORT);
t.show();
Rollno.setText("");
Name.setText("");
Course.setText("");
Rollno.requestFocus();
}
}
if(arg0==Deletee)
{
if(Rollno.getText().toString().length()==0)
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter Roll Number", Toast.LENGTH_SHORT);
t.show();
}
Cursor c=db.rawQuery("SELECT * FROM mystudents WHERE rollno='"+Rollno.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM mystudents WHERE rollno='"+Rollno.getText()+"'");
Toast t = Toast.makeText(getApplicationContext(), "Deleted Sucessfully", Toast.LENGTH_SHORT);
t.show();
Rollno.setText("");
Name.setText("");
Course.setText("");
Rollno.requestFocus();
}
else
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter correct Roll Number", Toast.LENGTH_SHORT);
t.show();
}
}
if(arg0==Update)
{
if(Rollno.getText().toString().length()==0)
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter Roll Number", Toast.LENGTH_SHORT);
t.show();
return;
}
Cursor c=db.rawQuery("SELECT * FROM mystudents WHERE rollno='"+Rollno.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE mystudents SET name='"+Name.getText()+"',Course='"+Course.getText()+
"' WHERE rollno='"+Rollno.getText()+"'");
Toast t = Toast.makeText(getApplicationContext(), "Updated Sucessfully", Toast.LENGTH_SHORT);
t.show();
}
else
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter correct Roll Number", Toast.LENGTH_SHORT);
t.show();
}
}
if(arg0==ViewAll)
{
Cursor c=db.rawQuery("SELECT * FROM mystudents", null);
if(c.getCount()==0)
{
Toast t = Toast.makeText(getApplicationContext(), "No Record", Toast.LENGTH_SHORT);
t.show();
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Rollno: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("Course: "+c.getString(2)+"\n\n");
}
ShowAll("Student Details", buffer.toString());
}
if(arg0==View)
{
if(Rollno.getText().toString().length()==0)
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter Roll Number", Toast.LENGTH_SHORT);
t.show();
return;
}
Cursor c=db.rawQuery("SELECT * FROM mystudents WHERE rollno='"+Rollno.getText()+"'", null);
if(c.moveToFirst())
{
Name.setText(c.getString(1));
Course.setText(c.getString(2));
}
else
{
Toast t = Toast.makeText(getApplicationContext(), "Please enter correct Roll Number", Toast.LENGTH_SHORT);
t.show();
}
}
}
public void ShowAll(String t,String m)
{
Builder b=new Builder(this);
b.setCancelable(true);
b.setTitle(t);
b.setMessage(m);
b.show();
}
}
Strings.Xml
StudentRegistration
Settings
Hello world!
Rollno :
Name :
Course :
Add
Delete
Update
View
View All
Show Information
activity_main.Xml
android:id="@+id/myLayout"
android:stretchColumns="0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_x="30dp"
android:layout_y="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:inputType="number"
android:layout_x="150dp"
android:layout_y="50dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
android:layout_x="30dp"
android:layout_y="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:inputType="text"
android:layout_x="150dp"
android:layout_y="100dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
android:layout_x="30dp"
android:layout_y="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:id="@+id/course"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_x="150dp"
android:layout_y="150dp"
android:inputType="text" />
android:stretchColumns="0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_y="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_x="150dp"
android:layout_y="50dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
android:layout_y="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_x="150dp"
android:layout_y="100dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
android:layout_y="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_x="150dp"
android:layout_y="150dp"
android:inputType="text" />
May 30, 2015
May 26, 2015
March 29, 2015
March 13, 2015
January 21, 2015
January 8, 2015
January 5, 2015
Say hello to HTML5
On 28 October 2014, World Wide Web Consortium (W3C) has just released HTML5, which is the fifth revision of HTML standard.
What's new in HTML 5
The most interesting new API's are:
- HTML Geolocation
- HTML Drag and Drop
- HTML Local Storage
- HTML Application Cache
- HTML Web Workers
- HTML SSE
January 1, 2015
Subscribe to:
Posts (Atom)