private void btnlogin_Click(object sender, EventArgs e)
{
login();
}
private void ClearFields()
{
txtusername.Text = String.Empty;
txtpwd.Text = String.Empty;
}
private void btncancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtpwd_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
login();
}
}
private void login()
{
try
{
ConnectionClass l_ConnectionClass = new ConnectionClass();
DataSet l_UserDataSet = l_ConnectionClass.FetchDataInDataSet("select * from tbluserlogin where userName = '" + txtusername.Text.ToLower().Trim() + "' and userPwd = '" + txtpwd.Text.Trim() + "'");
if (l_UserDataSet.Tables[0].Rows.Count > 0)
{
PublicVariables.CheckLoginFlag = true;
PublicVariables.OSUserID = Convert.ToInt16(l_UserDataSet.Tables[0].Rows[0]["userId"]);
PublicVariables.UserRole = l_UserDataSet.Tables[0].Rows[0]["userRole"].ToString();
DateTime getdatefrm = l_ConnectionClass.getlogouttime();
DateTime datenow = DateTime.Now;
if ((getdatefrm.AddMinutes(0) > datenow) && (getdatefrm != DateTime.MinValue))
{
MessageBox.Show("please wait");
ClearFields();
PublicVariables.CheckLoginFlag = false;
}
else
{
l_ConnectionClass.updateuserlogin();
Close();
this.Hide();
}
}
else
{
MessageBox.Show("Login Failed !!!!", "Error", MessageBoxButtons.OK);
PublicVariables.CheckLoginFlag = false;
txtusername.Text = "";
txtpwd.Text = "";
txtusername.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show("Connection Failed. Plz Check your Network Cable Connection", "Error", MessageBoxButtons.OK);
}
}
private void txtusername_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
txtpwd.Focus();
}
}
Saturday, October 30, 2010
Thursday, October 14, 2010
Sql Connection String Examples
Using C#:
using System.Data.SqlClient;
...
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString = "Data Source=(local);" +
"Initial Catalog=mySQLServerDBName;" +
"Integrated Security=yes";
oSQLConn.Open(); If connection to a remote server (via IP address):
oSQLConn.ConnectionString = "Network Library=DBMSSOCN;" & _ "Data Source=xxx.xxx.xxx.xxx,1433;" & _ "Initial Catalog=mySQLServerDBName;" & _ "User ID=myUsername;" & _ "Password=myPassword" Where: - "Network Library=DBMSSOCN" tells SqlConnection to use TCP/IP Q238949
- xxx.xxx.xxx.xxx is an IP address.
- 1433 is the default port number for SQL Server. Q269882 and Q287932
- You can also add "Encrypt=yes" for encryption
Connection String Examples
| Data source | Example | Description |
|---|---|---|
| SQL Server database on the local server | data source="(local)";initial catalog=AdventureWorks | Set data source type to SQL Server. |
| SQL Server instance database | Data Source=localhost\MSSQL10_50.InstanceName; Initial Catalog= AdventureWorks | Set data source type to SQL Server. |
| SQL Server Express database | Data Source=localhost\MSSQL10_50.SQLEXPRESS; Initial Catalog= AdventureWorks | Set data source type to SQL Server. |
| Analysis Services database on the local server | data source=localhost;initial catalog=Adventure Works DW | Set data source type to SQL Server Analysis Services. |
| SharePoint List | data source=http://MySharePointWeb/MySharePointSite/ | Set data source type to SharePoint List. |
| SQL Server 2000 Analysis Services server | provider=MSOLAP.2;data source= | Set the data source type to OLE DB Provider for OLAP Services 8.0. You can achieve a faster connection to SQL Server 2000 Analysis Services data sources if you set the ConnectTo property to 8.0. To set this property, use the Connection Properties dialog box, Advanced Properties tab. |
| Report Models | Not applicable. | You do not need a connection string for a report model. In Report Builder, browse to the report server and select the .smdl file that is the report model. |
| Oracle server | data source=myserver | Set the data source type to Oracle. The Oracle client tools must be installed on the Report Builder computer and on the report server. |
| SAP NetWeaver BI data source | DataSource=http://mySAPNetWeaverBIServer:8000/sap/bw/xml/soap/xmla | Set the data source type to SAP NetWeaver BI. |
| Hyperion Essbase data source | Data Source=http://localhost:13080/aps/XMLA; Initial Catalog=Sample | Set the data source type to Hyperion Essbase. |
| Teradata data source | data source= | Set the data source type to Teradata. The connection string is an Internet Protocol (IP) address in the form of four fields, where each field can be from one to three digits. |
| Teradata data source | Database= | Set the data source type to Teradata, similar to the previous example. Only use the default database that is specified in the Database tag, and do not automatically discover data relationships. |
| XML data source, Web service | data source=http://adventure-works.com/results.aspx | Set the data source type to XML. The connection string is a URL for a web service that supports Web Services Definition Language (WSDL). |
| XML data source, XML document | http://localhost/XML/Customers.xml | Set the data source type to XML. The connection string is a URL to the XML document. |
| XML data source, embedded XML document | Empty | Set the data source type to XML. The XML data is embedded in the report definition. |
Thursday, September 23, 2010
Tuesday, September 21, 2010
Date Select On Show DataGridView
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
DateTime dt = new DateTime();
dt = Convert.ToDateTime(dateTimePicker1.Value.ToShortDateString());
SqlCommand cmd = new SqlCommand();
string sqlqry = "select mbrchrg AS MemberCharge,costumechrg AS CostumerCharge,Date from swimpool where Date = '" + dt + "'";
dataGridView1.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "swimpool");
dataGridView1.DataSource = ds.Tables["swimpool"].DefaultView;
-------------------------------------------------------------------------
namespace HotelManagement
{
public partial class User_Record : Form
{
Dbclass db = new Dbclass();
string common;
public User_Record()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void User_Record_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string str = "select Addmminisator,User_Id,User_Type,User_Name,User_Password from user_master";
dt = db.FindFun(str);
grduser_record.DataSource = dt;
totalrecord.Text = Convert.ToInt32(grduser_record.Rows.Count - 1).ToString();
}
private void btnpreview_Click(object sender, EventArgs e)
{
Crstluser_master use = new Crstluser_master();
Frmviewr view = new Frmviewr();
DataTable dt = new DataTable();
string str = " Select * from user_Master";
dt = db.FindFun(str);
use.SetDataSource(dt);
view.crstlviewer.ReportSource = use;
view.Show();
}
}
}
SqlConnection con = new SqlConnection(constring);
DateTime dt = new DateTime();
dt = Convert.ToDateTime(dateTimePicker1.Value.ToShortDateString());
SqlCommand cmd = new SqlCommand();
string sqlqry = "select mbrchrg AS MemberCharge,costumechrg AS CostumerCharge,Date from swimpool where Date = '" + dt + "'";
dataGridView1.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "swimpool");
dataGridView1.DataSource = ds.Tables["swimpool"].DefaultView;
-------------------------------------------------------------------------
namespace HotelManagement
{
public partial class User_Record : Form
{
Dbclass db = new Dbclass();
string common;
public User_Record()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void User_Record_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string str = "select Addmminisator,User_Id,User_Type,User_Name,User_Password from user_master";
dt = db.FindFun(str);
grduser_record.DataSource = dt;
totalrecord.Text = Convert.ToInt32(grduser_record.Rows.Count - 1).ToString();
}
private void btnpreview_Click(object sender, EventArgs e)
{
Crstluser_master use = new Crstluser_master();
Frmviewr view = new Frmviewr();
DataTable dt = new DataTable();
string str = " Select * from user_Master";
dt = db.FindFun(str);
use.SetDataSource(dt);
view.crstlviewer.ReportSource = use;
view.Show();
}
}
}
Thursday, September 16, 2010
Wednesday, September 8, 2010
Datagridview Data Print
/ dataGridView1 is the DataGridView to print
GridPrintDocument doc = new GridPrintDocument(this.dataGridView1,
this.dataGridView1.Font, true);
doc.DocumentName = "Preview Test";
doc.DefaultPageSettings.Landscape = true;
doc.DefaultPageSettings.PrinterSettings.FromPage = 1;
doc.DefaultPageSettings.PrinterSettings.ToPage = 3;
PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
printPreviewDialog.ClientSize = new Size(400, 300);
printPreviewDialog.Location = new Point(29, 29);
printPreviewDialog.Name = "Print Preview Dialog";
printPreviewDialog.UseAntiAlias = true;
printPreviewDialog.Document = doc;
printPreviewDialog.ShowDialog();
doc.Dispose();
doc = null;
Saturday, September 4, 2010
Static DroupDownList Us In DataGridView
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;
using System.Data.SqlClient;
namespace Bar_nd_Hotel
{
public partial class SearchAll : Form
{
DAL obj = new DAL();
DataTable dt = new DataTable();
public SearchAll()
{
InitializeComponent();
}
private void SearchAll_Load(object sender, EventArgs e)
{
}
private void btnsearch_Click(object sender, EventArgs e)
{
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string selectval = Cmboselectitem.SelectedItem.ToString();
if (selectval == "Staff Details")
{
//string qry = "";
SqlCommand cmd = new SqlCommand();
string sqlqry = "Select * from crtstaff ";
if (txtname.Text != "")
{
sqlqry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtpost.Text != "")
{
sqlqry += "where post = '" + txtpost.Text + "' ";
}
else if (txtsalary.Text != "")
{
sqlqry += "where salary='" + txtsalary.Text + "'";
}
else if (txtmobileno.Text != "")
{
sqlqry += "where mobile_no='" + txtmobileno.Text + "'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlqry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
Searchgrid.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "crtstaff");
Searchgrid.DataSource = ds.Tables["crtstaff"].DefaultView;
}
if (selectval == "Salary Details")
{
string sqlry = "Select * from salarystatus ";
if (txtname.Text != "")
{
sqlry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtworkdays.Text != "")
{
sqlry += "where workdays ='" + txtworkdays.Text + "' ";
}
else if (chkdueamount.Checked == true)
{
sqlry += "where dueamt != '' and dueamt != '0'";
}
else if (chkpaidamount.Checked == true)
{
sqlry += "where paidamt !='' and paidamt != '0'";
}
else if (chkabsent.Checked == true)
{
sqlry += "where absent !='' and absent != '0'";
}
else if (chkdayshift.Checked == true)
{
sqlry += "where dayshift !='' and dayshift != '0'";
}
else if (chknight.Checked == true)
{
sqlry += "where nightshift !='' and nightshift != '0'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
SqlCommand cmd = new SqlCommand();
Searchgrid.DataSource = "";
cmd.CommandText = sqlry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "salarystatus");
Searchgrid.DataSource = ds.Tables["salarystatus"].DefaultView;
}
}
private void Cmboselectitem_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
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;
using System.Data.SqlClient;
namespace Bar_nd_Hotel
{
public partial class SearchAll : Form
{
DAL obj = new DAL();
DataTable dt = new DataTable();
public SearchAll()
{
InitializeComponent();
}
private void SearchAll_Load(object sender, EventArgs e)
{
}
private void btnsearch_Click(object sender, EventArgs e)
{
string constring = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=bar_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string selectval = Cmboselectitem.SelectedItem.ToString();
if (selectval == "Staff Details")
{
//string qry = "";
SqlCommand cmd = new SqlCommand();
string sqlqry = "Select * from crtstaff ";
if (txtname.Text != "")
{
sqlqry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtpost.Text != "")
{
sqlqry += "where post = '" + txtpost.Text + "' ";
}
else if (txtsalary.Text != "")
{
sqlqry += "where salary='" + txtsalary.Text + "'";
}
else if (txtmobileno.Text != "")
{
sqlqry += "where mobile_no='" + txtmobileno.Text + "'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlqry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
Searchgrid.DataSource = "";
cmd.CommandText = sqlqry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "crtstaff");
Searchgrid.DataSource = ds.Tables["crtstaff"].DefaultView;
}
if (selectval == "Salary Details")
{
string sqlry = "Select * from salarystatus ";
if (txtname.Text != "")
{
sqlry += "where stfname = '" + txtname.Text + "' ";
}
else if (txtworkdays.Text != "")
{
sqlry += "where workdays ='" + txtworkdays.Text + "' ";
}
else if (chkdueamount.Checked == true)
{
sqlry += "where dueamt != '' and dueamt != '0'";
}
else if (chkpaidamount.Checked == true)
{
sqlry += "where paidamt !='' and paidamt != '0'";
}
else if (chkabsent.Checked == true)
{
sqlry += "where absent !='' and absent != '0'";
}
else if (chkdayshift.Checked == true)
{
sqlry += "where dayshift !='' and dayshift != '0'";
}
else if (chknight.Checked == true)
{
sqlry += "where nightshift !='' and nightshift != '0'";
}
else if (dateTimePicker1.Value.ToShortDateString() != "")
{
sqlry += "where Date between '" + dateTimePicker1.Value.ToShortDateString() + "' and '" + dateTimePicker2.Value.ToShortDateString() + "'";
}
SqlCommand cmd = new SqlCommand();
Searchgrid.DataSource = "";
cmd.CommandText = sqlry;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "salarystatus");
Searchgrid.DataSource = ds.Tables["salarystatus"].DefaultView;
}
}
private void Cmboselectitem_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Subscribe to:
Posts (Atom)