Note : Project Downloading Link End of this Page
+-[ RELEASE INFO ]-------------------------------------------------------------+
| |
| - Name......: ComboBox Data Fetch From Table |
| - Date......: 2018-09-022 |
| |
| - Homepage..: http://csharinstructive.blogspot.com/
Thanks For Downloading Programme
If You Want More Programming Code and Tricks You Can Subscribe my Youtube Channel Link
| https://www.youtube.com/aminsati |
| ================================================================================ |
Programming Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace CSHARP_TUTORIAL
{
public partial class ComboBoxFetchingDataFromTable : Form
{
//Initialize Object For Connection Access Database
string scon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+Application.StartupPath+"\\DB_BANK.accdb;Persist Security Info=True";
OleDbCommand cmd = new OleDbCommand();
OleDbConnection con;
public ComboBoxFetchingDataFromTable()
{
InitializeComponent();
}
//For Fetch Records in From Database
private OleDbDataReader selection(string query)
{
con = new OleDbConnection(scon);
con.Open();
cmd.Connection = con;
cmd.CommandText = query;
OleDbDataReader dr = cmd.ExecuteReader();
return dr;
con.Close();
}
//For Fill Data in Specific Combobox
private void fillcombo(ComboBox cmb, string query)
{
cmb.Items.Clear();
OleDbDataReader dr = selection(query);
while (dr.Read() == true)
{
cmb.Items.Add(dr[0].ToString());
}
}
//For Insert Data in Table
private void insertdata()
{
string query="insert into tbl_deposits (fbankname,faccountname,faccountno,famount) values('"+cmb_bankname.Text +"','"+cmb_accountname.Text +"','"+cmb_accountno.Text+"',"+txt_amount.Text +")";
con = new OleDbConnection(scon);
con.Open();
cmd.Connection = con;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Save Data Successfully", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//Fetch Data in Combobx
private void fetchcombo()
{
string q1 = "select distinct fbankname from tbl_accountmaster";
fillcombo(cmb_bankname, q1);
string q2 = "select distinct faccountname from tbl_accountmaster";
//where fbankname='" + cmb_bankname.Text + "'";
fillcombo(cmb_accountname, q2);
string q3 = "select distinct faccountno from tbl_accountmaster";
//where faccountname='" + cmb_accountname.Text + "'";
fillcombo(cmb_accountno, q3);
}
private void btnclose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnclose1_Click(object sender, EventArgs e)
{
this.Close();
}
private void ComboBoxFetchingDataFromTable_Load(object sender, EventArgs e)
{
fetchcombo();
}
private void btnsave_Click(object sender, EventArgs e)
{
insertdata();
}
private void cmb_accountname_Leave(object sender, EventArgs e)
{
string q3 = "select distinct faccountno from tbl_accountmaster where faccountname='" + cmb_accountname.Text + "'";
fillcombo(cmb_accountno, q3);
}
private void cmb_bankname_Leave(object sender, EventArgs e)
{
string q2 = "select distinct faccountname from tbl_accountmaster where fbankname='" + cmb_bankname.Text + "'";
fillcombo(cmb_accountname, q2);
}
private void lblsubscribe_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://www.youtube.com/aminsati");
}
}
}
1 Comments
لا استطيع تØميل المشروع
ReplyDelete