C#.Net : Retrieving Value in Sql Server[Passing only Query]

public class LBSqlConnection
{
private SqlConnection objCon;
public static string DataSource = “LOCALHOST”;
SqlCommand Cmd;
public SqlConnection getConnection() //Get Localhost Sql Connection
{
try
{
SqlConnection  con = new SqlConnection(“Data Source=” + DataSource + “;Initial Catalog=DBName;Integrated Security=True”);
return con;
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
return new SqlConnection();
}

public int IUDRecord(String IUDString) // IUD [Insert, Update, Delete]
{
objCon = getConnection();
objCon.Open();
try
{
Cmd = new SqlCommand(IUDString, objCon);
int i = Cmd.ExecuteNonQuery();
objCon.Close();
return i;
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
finally
{
Cmd.Dispose();
}
return new int();
}

public DataSet DataView(string Data) // [Select]
{
objCon = getConnection();
SqlDataAdapter Ada;
DataSet ds;
objCon.Open();

try
{
Cmd = new SqlCommand(Data, objCon);
Ada = new SqlDataAdapter(Cmd);
ds = new DataSet();
Ada.Fill(ds);
objCon.Close();
return ds;
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
finally
{
Cmd.Dispose();
}

return new DataSet();
}

public void Datagrid(DataGridView DGV,string Data) //Fill Datagrid
{
objCon = getConnection();
SqlDataAdapter Ada;
DataSet ds;
objCon.Open();
try
{
Cmd = new SqlCommand(Data, objCon);
Ada = new SqlDataAdapter(Cmd);
ds = new DataSet();
Ada.Fill(ds);
//DGV.DataSource = null;
DGV.DataSource = ds.Tables[0];
objCon.Close();

}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
finally
{
Cmd.Dispose();
}
}

public void ComboValue(ComboBox CMB,string Data, string Display, string Value) // Fill ComboBox
{
objCon = getConnection();
SqlDataAdapter Ada;
DataSet ds;
objCon.Open();
try
{
Cmd = new SqlCommand(Data, objCon);
Ada = new SqlDataAdapter(Cmd);
ds = new DataSet();
Ada.Fill(ds);
CMB.DisplayMember = Display;
CMB.ValueMember = Value;
CMB.DataSource = ds.Tables[0];
objCon.Close();

}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
finally
{
Cmd.Dispose();
}
}

public DataSet vView(string ViewQuery,DataTable DT)
{
objCon = getConnection();
SqlDataAdapter Ada;
DataSet ds;
objCon.Open();
try
{
try
{
Cmd = new SqlCommand(“Drop View RpView”, objCon);
Cmd.ExecuteNonQuery();
}
catch (Exception Ex)
{

}

string xx = “Create View RpView As ” + ViewQuery;
Cmd = new SqlCommand(xx, objCon);
Cmd.ExecuteNonQuery();

Cmd = new SqlCommand(“Select * from RpView”, objCon);
Ada = new SqlDataAdapter(Cmd);
ds = new DataSet();
Ada.Fill(ds);
Ada.Fill(DT);
objCon.Close();
return ds;
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
finally
{
Cmd.Dispose();
}

return new DataSet();
}

public void ScaleDown(System.Windows.Forms.Form frm)
{
int scrWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
int scrHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
if (scrWidth < frm.Width)
{
foreach (System.Windows.Forms.Control cntrl in frm.Controls)
{
cntrl.Width = ((cntrl.Width) * (scrWidth)) / (frm.Width);
cntrl.Left = ((cntrl.Left) * (scrWidth)) / (frm.Width);
}
}

if (scrHeight < frm.Height)
{
foreach (System.Windows.Forms.Control cntrl in frm.Controls)
{
cntrl.Height = ((cntrl.Height) * (scrHeight)) / (frm.Height);
cntrl.Top = ((cntrl.Top) * (scrHeight)) / (frm.Height);
}
}
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: