//First download xpiinstall.exe and install into your system.
applet code="JavaFile.class" width="100%" codebase="CodePath" height="40" archive="JavaFile.jar">
param value="CodePath" name="url" />
param value="" name="dataurl" />
/applet>*/
ASP.NET MVC, C#, MS SQL Server, EF, MySql Server, Linq, Jquery, Java Script, Interview Questions. If you are looking for updates than kindly subscribe with this blog.
Monday, March 22, 2010
Friday, March 12, 2010
How to create dynamically LinkButton with Literal Control in ASP.NET
Step 1 : First take following control into the .aspx page.
asp:UpdatePanel id="up1" runat="server">
contenttemplate>
asp:Literal ID="lt1" Text="" runat="server">
asp:PlaceHolder ID="ph1" runat="server">
/asp:PlaceHolder>
/contenttemplate>
/asp:UpdatePanel>
Step 2 :
string query = query for fill the dataset;
DataSet ds = new DataSet();
ds = pass the query to retrive data;
int i = 0;
LinkButton lt = new LinkButton();
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
lt = new LinkButton();
lt.ID = "link" + i.ToString();
lt.Text = ds.Tables[0].Rows[i].ItemArray[1].ToString();
ph1.Controls.Add(lt);
ph1.Controls.Add(new LiteralControl("
"));
}
asp:UpdatePanel id="up1" runat="server">
contenttemplate>
asp:Literal ID="lt1" Text="" runat="server">
asp:PlaceHolder ID="ph1" runat="server">
/asp:PlaceHolder>
/contenttemplate>
/asp:UpdatePanel>
Step 2 :
string query = query for fill the dataset;
DataSet ds = new DataSet();
ds = pass the query to retrive data;
int i = 0;
LinkButton lt = new LinkButton();
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
lt = new LinkButton();
lt.ID = "link" + i.ToString();
lt.Text = ds.Tables[0].Rows[i].ItemArray[1].ToString();
ph1.Controls.Add(lt);
ph1.Controls.Add(new LiteralControl("
"));
}
Thursday, March 11, 2010
How to use Ajax : CollapsiblePanelExtender in ASP.NET
//It is simple method, Other properties will be set which you want
Step 1: Take one panel and all the content you want to collapse put into this panel.
Step 2: Set the Collapsed Property true.
Step 3: ExpandControlID/CollapseControlID : The Controls that will expand or collapse the panel on a click, respectively. If these values are the same, the panel will automatically toggle its state on each click.
Step 4: TargetControlID is PanelID
Step 5: Select Panel and Set the Property SuppressPostBack="True"
Step 1: Take one panel and all the content you want to collapse put into this panel.
Step 2: Set the Collapsed Property true.
Step 3: ExpandControlID/CollapseControlID : The Controls that will expand or collapse the panel on a click, respectively. If these values are the same, the panel will automatically toggle its state on each click.
Step 4: TargetControlID is PanelID
Step 5: Select Panel and Set the Property SuppressPostBack="True"
How to use Ajax : Hovermenu Extender in ASP.NET
// It is a simple method, Other properties set by you which you want
Step 1. Take the control that the extender is targeting.When the mouse cursor is over this control,the hover menu popup will be displayed.
Step 2. Take one panel to display when mouse is over the target control
Step 3. Set the following properties:
TargetControlID = "ID of the panel or control which display when mouse is over the target control"
PopupControlID = "ID of the control that the extender is targeting"
PopupPosition = Left (Default), Right, Top, Bottom, Center.
Step 1. Take the control that the extender is targeting.When the mouse cursor is over this control,the hover menu popup will be displayed.
Step 2. Take one panel to display when mouse is over the target control
Step 3. Set the following properties:
TargetControlID = "ID of the panel or control which display when mouse is over the target control"
PopupControlID = "ID of the control that the extender is targeting"
PopupPosition = Left (Default), Right, Top, Bottom, Center.
Wednesday, March 3, 2010
Web Application : How to upload multiple images at a time
//First add image control into the web form how many you want to upload images at a time
//Add one button
//Write the below code into the button_click event
if (FileUpload1.HasFile)
{
string imagefile = FileUpload1.FileName;
if (CheckFileType(imagefile) == true)
{
Random rndob = new Random();
int db = rndob.Next(1, 100);
filename = System.IO.Path.GetFileNameWithoutExtension(imagefile) + db.ToString() + System.IO.Path.GetExtension(imagefile);
String FilePath = "images/" + filename;
FileUpload1.SaveAs(Server.MapPath(FilePath));
objimg.ImageName = filename;
Image1();
if (Session["imagecount"].ToString() == "1")
{
Img1.ImageUrl = FilePath;
ViewState["img1"] = FilePath;
}
else if (Session["imagecount"].ToString() == "2")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = FilePath;
ViewState["img2"] = FilePath;
}
else if (Session["imagecount"].ToString() == "3")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = ViewState["img2"].ToString();
Img3.ImageUrl = FilePath;
ViewState["img3"] = FilePath;
}
else if (Session["imagecount"].ToString() == "4")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = ViewState["img2"].ToString();
Img3.ImageUrl = ViewState["img3"].ToString();
Img4.ImageUrl = FilePath;
ViewState["img4"] = FilePath;
}
else if (Session["imagecount"].ToString() == "5")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = ViewState["img2"].ToString();
Img3.ImageUrl = ViewState["img3"].ToString();
Img4.ImageUrl = ViewState["img4"].ToString();
Img5.ImageUrl = FilePath;
ViewState["img5"] = FilePath;
}
}
}
//execption handling
else
{
lblErrMsg.Visible = true;
lblErrMsg.Text = "";
lblErrMsg.Text = "please select a file";
}
}
//if file extension belongs to these list then only allowed
public bool CheckFileType(string filename)
{
string ext;
ext = System.IO.Path.GetExtension(filename);
switch (ext.ToLower())
{
case ".gif":
return true;
case ".jpeg":
return true;
case ".jpg":
return true;
case ".bmp":
return true;
case ".png":
return true;
default:
return false;
}
}
//Add one button
//Write the below code into the button_click event
if (FileUpload1.HasFile)
{
string imagefile = FileUpload1.FileName;
if (CheckFileType(imagefile) == true)
{
Random rndob = new Random();
int db = rndob.Next(1, 100);
filename = System.IO.Path.GetFileNameWithoutExtension(imagefile) + db.ToString() + System.IO.Path.GetExtension(imagefile);
String FilePath = "images/" + filename;
FileUpload1.SaveAs(Server.MapPath(FilePath));
objimg.ImageName = filename;
Image1();
if (Session["imagecount"].ToString() == "1")
{
Img1.ImageUrl = FilePath;
ViewState["img1"] = FilePath;
}
else if (Session["imagecount"].ToString() == "2")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = FilePath;
ViewState["img2"] = FilePath;
}
else if (Session["imagecount"].ToString() == "3")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = ViewState["img2"].ToString();
Img3.ImageUrl = FilePath;
ViewState["img3"] = FilePath;
}
else if (Session["imagecount"].ToString() == "4")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = ViewState["img2"].ToString();
Img3.ImageUrl = ViewState["img3"].ToString();
Img4.ImageUrl = FilePath;
ViewState["img4"] = FilePath;
}
else if (Session["imagecount"].ToString() == "5")
{
Img1.ImageUrl = ViewState["img1"].ToString();
Img2.ImageUrl = ViewState["img2"].ToString();
Img3.ImageUrl = ViewState["img3"].ToString();
Img4.ImageUrl = ViewState["img4"].ToString();
Img5.ImageUrl = FilePath;
ViewState["img5"] = FilePath;
}
}
}
//execption handling
else
{
lblErrMsg.Visible = true;
lblErrMsg.Text = "";
lblErrMsg.Text = "please select a file";
}
}
//if file extension belongs to these list then only allowed
public bool CheckFileType(string filename)
{
string ext;
ext = System.IO.Path.GetExtension(filename);
switch (ext.ToLower())
{
case ".gif":
return true;
case ".jpeg":
return true;
case ".jpg":
return true;
case ".bmp":
return true;
case ".png":
return true;
default:
return false;
}
}
How to submit a form on pressing enter key
function clickButton(e, buttonid)
{
var bt = document.getElementById(buttonid);
if (typeof bt == 'object'){
if(navigator.appName.indexOf("Netscape")>(-1)){
if (e.keyCode == 13){
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
{
if (event.keyCode == 13){
bt.click();
return false;
}
}
}
}
//Call this function on last text box of a form with onKeyPress="clickButton(this)"
{
var bt = document.getElementById(buttonid);
if (typeof bt == 'object'){
if(navigator.appName.indexOf("Netscape")>(-1)){
if (e.keyCode == 13){
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
{
if (event.keyCode == 13){
bt.click();
return false;
}
}
}
}
//Call this function on last text box of a form with onKeyPress="clickButton(this)"
Saturday, February 20, 2010
Wednesday, February 10, 2010
How to select and deselect checkbox field into the GridView
//JavaScript function for Select and Deselect checkbox field in GridView
function SelectDeselectAll(chkAll)
{
var a = document.forms[0];
var i=0;
for(i=0;i lessthansign a.length;i++)
{
if(a[i].name.indexOf("chkItem") != -1)
{
a[i].checked = chkAll.checked;
}
}
}
function DeselectChkAll(chk)
{
var c=0;
var d=1;
var a = document.forms[0];
//alert(a.length);
if(chk.checked == false)
{
document.getElementById("chkAll").checked = chk.checked;
}
else
{
for(i=0;i lessthansign a.length;i++)
{
if(a[i].name.indexOf("chkItem") != -1)
{
if(a[i].checked==true)
{
c=1;
}
else
{
d=0;
}
}
}
if(d != 0)
{
document.getElementById("chkAll").checked =true;
}
}
}
//How to use this function
asp:TemplateField>
input id="Checkbox1" runat="server" onclick="javascript:SelectDeselectAll(this);" type="checkbox" />
/HeaderTemplate>
/asp:GridView>columns>
asp:TemplateField>headertemplate>
input id="chkAll" runat="server" onclick="javascript:SelectDeselectAll(this);" type="checkbox" />
/HeaderTemplate>
function SelectDeselectAll(chkAll)
{
var a = document.forms[0];
var i=0;
for(i=0;i lessthansign a.length;i++)
{
if(a[i].name.indexOf("chkItem") != -1)
{
a[i].checked = chkAll.checked;
}
}
}
function DeselectChkAll(chk)
{
var c=0;
var d=1;
var a = document.forms[0];
//alert(a.length);
if(chk.checked == false)
{
document.getElementById("chkAll").checked = chk.checked;
}
else
{
for(i=0;i lessthansign a.length;i++)
{
if(a[i].name.indexOf("chkItem") != -1)
{
if(a[i].checked==true)
{
c=1;
}
else
{
d=0;
}
}
}
if(d != 0)
{
document.getElementById("chkAll").checked =true;
}
}
}
//How to use this function
asp:TemplateField>
input id="Checkbox1" runat="server" onclick="javascript:SelectDeselectAll(this);" type="checkbox" />
/HeaderTemplate>
/asp:GridView>
asp:TemplateField>headertemplate>
input id="chkAll" runat="server" onclick="javascript:SelectDeselectAll(this);" type="checkbox" />
/HeaderTemplate>
How to use Ajax Validator Collout Extender
Steps:-
Step 1 : Insert any validation control with textbox
Step 2 : Insert Validator Collout Extender with validation control from the Ajax Control Toolkit
Step 3 : Set the property of the Validation control : ControlToValidate,ErrorMessage,SetFocusOnError=True,Display=none and Give the proper name to the validation control
Step 4 : Set the ValidationControlID into the Validator collout Extender Property TargetControlID
Step 1 : Insert any validation control with textbox
Step 2 : Insert Validator Collout Extender with validation control from the Ajax Control Toolkit
Step 3 : Set the property of the Validation control : ControlToValidate,ErrorMessage,SetFocusOnError=True,Display=none and Give the proper name to the validation control
Step 4 : Set the ValidationControlID into the Validator collout Extender Property TargetControlID
C# window application : How to validate mobile no.
//First : Simple Method
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == true)
{
if (textBox1.Text.Length < 10) { //do nothing } else { MessageBox.Show("Max 10 chars"); e.Handled = true; } } else { e.Handled = true; } } //Second Method using System.Text.RegularExpressions; private void btnValidatePhoneNumber_Click(object sender, EventArgs e) { Regex re = new Regex("^9[0-9]{9}"); if(re.IsMatch(txtPhone.Text.Trim()) == false || txtPhone.Text.Length>10)
{
MessageBox.Show("Invalid Indian Mobile Number !!");
txtPhone.Focus();
}
}
//With the help of JavaScript
function phone_validate(phone)
{
var phoneReg = ^((\+)?(\d{2}[-]))?(\d{10}){1}?$;
if(phoneReg.test(phone) == false)
{
alert("Phone number is not yet valid.");
}
else
{
alert("You have entered a valid phone number!");
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == true)
{
if (textBox1.Text.Length < 10) { //do nothing } else { MessageBox.Show("Max 10 chars"); e.Handled = true; } } else { e.Handled = true; } } //Second Method using System.Text.RegularExpressions; private void btnValidatePhoneNumber_Click(object sender, EventArgs e) { Regex re = new Regex("^9[0-9]{9}"); if(re.IsMatch(txtPhone.Text.Trim()) == false || txtPhone.Text.Length>10)
{
MessageBox.Show("Invalid Indian Mobile Number !!");
txtPhone.Focus();
}
}
//With the help of JavaScript
function phone_validate(phone)
{
var phoneReg = ^((\+)?(\d{2}[-]))?(\d{10}){1}?$;
if(phoneReg.test(phone) == false)
{
alert("Phone number is not yet valid.");
}
else
{
alert("You have entered a valid phone number!");
}
}
Tuesday, February 9, 2010
How to load Image in C# and set properties of the Picture Box
Create a C# application drag a picture Box, four buttons and open file dialog on the form.
Write code on btn_browse Button click
-----------------------------------------
private void btn_browse_Click(object sender, System.EventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog()==DialogResult.OK)
{
pictureBox1.Image = new Bitmap(open.FileName);
}
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
Write code on btn_StretchImage Button click
------------------------------------------------
private void btn_StretchImage_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
}
Write code on btn_AutoSize Button click
-------------------------------------------------
private void btn_AutoSize_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
}
Write code on btn_CenterImage Button click
--------------------------------------------------
private void btn_CenterImage_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
}
Write code on btn_browse Button click
-----------------------------------------
private void btn_browse_Click(object sender, System.EventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog()==DialogResult.OK)
{
pictureBox1.Image = new Bitmap(open.FileName);
}
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
Write code on btn_StretchImage Button click
------------------------------------------------
private void btn_StretchImage_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
}
Write code on btn_AutoSize Button click
-------------------------------------------------
private void btn_AutoSize_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
}
Write code on btn_CenterImage Button click
--------------------------------------------------
private void btn_CenterImage_Click(object sender, System.EventArgs e)
{
pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
}
Monday, February 8, 2010
Thursday, February 4, 2010
C# window application : How to pass the value from one page to another
//In Mdi Form
//Declare the variable, which you want to pass
string userid;
string password;
FormName obj = new FormName(userid,password);
obj.MdiParent = this;
obj.Show();
//In Other Form
//Declare the variable, which you want to pass
string userid;
string password;
public FormName(string uid1,string psw)
{
userid = uid1;
password = psw;
InitializeComponent();
}
//Declare the variable, which you want to pass
string userid;
string password;
FormName obj = new FormName(userid,password);
obj.MdiParent = this;
obj.Show();
//In Other Form
//Declare the variable, which you want to pass
string userid;
string password;
public FormName(string uid1,string psw)
{
userid = uid1;
password = psw;
InitializeComponent();
}
Thursday, January 28, 2010
Passing data from one database to another database table (Access) (C#)
string conString = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Backup.mdb;Jet
OLEDB:Database Password=12345";
OleDbConnection dbconn = new OleDbConnection();
OleDbDataAdapter dAdapter = new OleDbDataAdapter();
OleDbCommand dbcommand = new OleDbCommand();
try
{
if (dbconn.State == ConnectionState.Closed)
dbconn.Open();
string selQuery = "INSERT INTO [Master] SELECT * FROM [MS Access;DATABASE="+
"\\Data.mdb" + ";].[Master]";
dbcommand.CommandText = selQuery;
dbcommand.CommandType = CommandType.Text;
dbcommand.Connection = dbconn;
int result = dbcommand.ExecuteNonQuery();
}
catch(Exception ex) {}
OLEDB:Database Password=12345";
OleDbConnection dbconn = new OleDbConnection();
OleDbDataAdapter dAdapter = new OleDbDataAdapter();
OleDbCommand dbcommand = new OleDbCommand();
try
{
if (dbconn.State == ConnectionState.Closed)
dbconn.Open();
string selQuery = "INSERT INTO [Master] SELECT * FROM [MS Access;DATABASE="+
"\\Data.mdb" + ";].[Master]";
dbcommand.CommandText = selQuery;
dbcommand.CommandType = CommandType.Text;
dbcommand.Connection = dbconn;
int result = dbcommand.ExecuteNonQuery();
}
catch(Exception ex) {}
How to create an Access database by using ADOX and Visual C# .NET
Build an Access Database
1. Open a new Visual C# .NET console application.
2. In Solution Explorer, right-click the References node and select Add Reference.
3. On the COM tab, select Microsoft ADO Ext. 2.7 for DDL and Security, click Select to add it to the Selected Components, and then click OK.
4. Delete all of the code from the code window for Class1.cs.
5. Paste the following code into the code window:
using System;
using ADOX;
private void btnCreate_Click(object sender, EventArgs e)
{
ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source=D:\\NewMDB.mdb;" +"Jet OLEDB:Engine Type=5");
MessageBox.Show("Database Created Successfully");
cat = null;
}
1. Open a new Visual C# .NET console application.
2. In Solution Explorer, right-click the References node and select Add Reference.
3. On the COM tab, select Microsoft ADO Ext. 2.7 for DDL and Security, click Select to add it to the Selected Components, and then click OK.
4. Delete all of the code from the code window for Class1.cs.
5. Paste the following code into the code window:
using System;
using ADOX;
private void btnCreate_Click(object sender, EventArgs e)
{
ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source=D:\\NewMDB.mdb;" +"Jet OLEDB:Engine Type=5");
MessageBox.Show("Database Created Successfully");
cat = null;
}
Wednesday, January 27, 2010
Pager Control for Repeater, DataList
http://www.codeproject.com/KB/custom-controls/CollectionPager.aspx?fid=160845&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=251
Friday, January 22, 2010
How to use Crystal Report into the ASP.NET
using CrystalDecisions.CrystalReports.Engine;
protected void Page_Load(object sender, EventArgs e)
{
ConfigureReport();
}
private void ConfigureReport()
{
ReportDocument mydoc = new ReportDocument();
string reportPath = Server.MapPath("Report.rpt");
mydoc.Load(reportPath);
CrystalReportViewer1.ReportSource = mydoc;
CrystalReportViewer1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
ConfigureReport();
}
private void ConfigureReport()
{
ReportDocument mydoc = new ReportDocument();
string reportPath = Server.MapPath("Report.rpt");
mydoc.Load(reportPath);
CrystalReportViewer1.ReportSource = mydoc;
CrystalReportViewer1.DataBind();
}
Disable Typing in Combobox in C# window application
//Disable Typing in Combobox in C# window application
Set the Combobox DropDownStyle property to : DropDownList
Set the Combobox DropDownStyle property to : DropDownList
How to clear all the textbox/groupbox on single click
public void ClearTextBox(Form f)
{
for (int i = 0; i < f.Controls.Count; i++)
{
if (f.Controls[i] is TextBox)
{
f.Controls[i].Text = "";
}
else if (f.Controls[i] is GroupBox)
{
for (int j = 0; j < f.Controls[i].Controls.Count; j++)
{
if (f.Controls[i].Controls[j] is TextBox)
{
f.Controls[i].Controls[j].Text = "";
}
}
}
}
}
//How to call this function(Into the Submit Button)
Make a object from the Program.cs file.
object.ClearTextBox(this);
//After submit query
{
for (int i = 0; i < f.Controls.Count; i++)
{
if (f.Controls[i] is TextBox)
{
f.Controls[i].Text = "";
}
else if (f.Controls[i] is GroupBox)
{
for (int j = 0; j < f.Controls[i].Controls.Count; j++)
{
if (f.Controls[i].Controls[j] is TextBox)
{
f.Controls[i].Controls[j].Text = "";
}
}
}
}
}
//How to call this function(Into the Submit Button)
Make a object from the Program.cs file.
object.ClearTextBox(this);
//After submit query
Monday, January 18, 2010
Window Application : C# Function for Insert,get data and fill the dropdown list
//To get data from database
string constr;
constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\database.mdb";
public object getdata(string str)
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
object a;
OleDbCommand cmd = new OleDbCommand(str, con);
a = cmd.ExecuteScalar();
con.Close();
return a;
}
//To inserting data into the database
public void insertdata(string str)
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
}
//To fill the dropdownlist
public void dataset(ComboBox ddl, string str)
{
OleDbConnection con = new OleDbConnection(constr);
OleDbDataAdapter dap = new OleDbDataAdapter(str, con);
con.Open();
DataSet ds = new DataSet();
dap.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[i].ItemArray[0].ToString()))
{
ddl.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
con.Close();
}
string constr;
constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\database.mdb";
public object getdata(string str)
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
object a;
OleDbCommand cmd = new OleDbCommand(str, con);
a = cmd.ExecuteScalar();
con.Close();
return a;
}
//To inserting data into the database
public void insertdata(string str)
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
}
//To fill the dropdownlist
public void dataset(ComboBox ddl, string str)
{
OleDbConnection con = new OleDbConnection(constr);
OleDbDataAdapter dap = new OleDbDataAdapter(str, con);
con.Open();
DataSet ds = new DataSet();
dap.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[i].ItemArray[0].ToString()))
{
ddl.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
con.Close();
}
Subscribe to:
Comments (Atom)