How to connect infobright DB through perl ?
With DBD-mysql. Install it with
perl Makefile.PL --mysql_config=/usr/local/infobright-3.5.2-x86_64/bin/mysql_config
or similar.
You can connect to Infobright using any standard database connection that you'd use with MySQL. Daxim is correct -- DBD is one of the most common ways to connect to the database. In your DBD config, all you'd need to do is change the port number from 3306 (MysQL) to 5029 (Infobright). All the rest is the same.
**INSERT **
if (textBox4.Text == "")
{
MessageBox.Show("Please provide Selling1 ", "Item Update", MessageBoxButtons.OK);
textBox4.Focus();
return;
}
int i = dbcon.writer("insert into Item_Master(Item_Code,Name,Description,Selling1,Selling2,Reorder_level,Reorder_Quantity,Active) Values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "')");
if (i == 1)
{
MessageBox.Show("Record added succesfully", "Item Table");
Itemview();//disply ll
iclear();
}
else
{ MessageBox.Show("Record unsuccesfully for Item "); }
}
**INSERT **
Dbcontrol dbcon = new Dbcontrol();
SqlDataReader dr = null;
string date = DateTime.Now.ToString("M/d/yyyy");
VIEW/SEARCH
listView1.Items.Clear();
dr = dbcon.reader("select cateid,brand,type,deta,date from emcategory where cateid like '%" + txtseacrchid.Text + "%'");
while (dr.Read())
{
string sid = dr["cateid"].ToString();
string id = dr["brand"].ToString();
string pname = dr["type"].ToString();
string dis = dr["deta"].ToString();
string tim = dr["date"].ToString();
string[] row = { sid, id, pname, dis, tim };
var listViewItem = new ListViewItem(row);
listView1.Items.Add(listViewItem);
}
VIEW/SEARCH*
**UPDATE **
try
{
DialogResult x = MessageBox.Show("Do You Really Want To Update This Record", "Cash Book Details", MessageBoxButtons.YesNo);
if (x == DialogResult.Yes)
{
upate.Enabled = true;
delete.Enabled = false;
foreach (ListViewItem item in listView1.SelectedItems)
{
txtid.Text = item.SubItems[0].Text;
txtBrand.Text = item.SubItems[1].Text;
txttyp.Text = item.SubItems[2].Text;
txtdec.Text = item.SubItems[3].Text;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
**UPDATE **
DELETE
DialogResult x = MessageBox.Show("Do You Really Want To Delete This Record", "Item Category", MessageBoxButtons.YesNo);
if (x == DialogResult.Yes)
{
delete.Enabled = true;
int i = dbcon.writer("delete from Ritemcategory where cateid='" + txtid.Text + "'");
if (i == 2 || i == 1)
{
MessageBox.Show("Deleted Succesfully", "Item Category");
view();
generatePid();
}
}
else
{
delete.Enabled = false;
}
DELETE
STOREDPROCEDURE
public void generatePid()
{
dr = dbcon.reader("Genarate_itemcategory_id");
while (dr.Read())
{
txtid.Text = dr["value"].ToString();
}
}
//////////////////KEYDOWN////////////
//////////////////
//////////////////KEYPRESS////////////
//////////////////
//////////////////SELECTEDVALUE////////////
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
upate.Enabled = false;
Save.Enabled = false;
delete.Enabled = true;
foreach (ListViewItem item in listView1.SelectedItems)
{
txtid.Text = item.SubItems[0].Text;
txtBrand.Text = item.SubItems[1].Text;
txttyp.Text = item.SubItems[2].Text;
txtdec.Text = item.SubItems[3].Text;
}
}
//////////////////
//////////////////KEYDOWN////////////
if (e.KeyCode == Keys.Enter)
{
insert();
}
//////////////////
public void log()
{
dr = dbcon.reader("select * from Admin where id = ' 1'");
while (dr.Read())
{
string un = dr["fuser"].ToString();
string ped = dr["fpassword"].ToString();
if ((textBox1.Text == "" || textBox1.Text == null) || (textBox2.Text == "" || textBox2.Text == null))
{
MessageBox.Show("Please enter username and password");
}
else
{
if (textBox1.Text == un && textBox2.Text == ped)
{
logdetail();
}
else
{
MessageBox.Show("User Name or Password is incorrect");
}
}
}
}
//////////////////KEYDOWN////////////
//////////////////
class Dataconnection
{
public static SqlConnection NewCon;
//public static string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
public static SqlConnection GetConnection()
{
NewCon = new SqlConnection("Data Source=Absar;Initial Catalog=star_fancy_stock;Integrated Security=True;");
return NewCon;
}
}
///////////////////////
2ND
//////////////////
namespace star_fancy_stock
{
class Dbcontrol
{
public static SqlConnection NewCon;
SqlDataReader dr;
public int dataread = 0;
public Dbcontrol()
{ }
public SqlDataReader reader(String sql)
{
try {
NewCon = Dataconnection.GetConnection();
NewCon.Open();
SqlCommand newconn = new SqlCommand(sql, NewCon);
dr = newconn.ExecuteReader();
return dr;
}
catch (Exception ex) { MessageBox.Show(ex.Message); return dr; }
}
public int writer(String sql)
{
try
{
dataread = 0;
NewCon = Dataconnection.GetConnection();
NewCon.Open();
SqlCommand newconn = new SqlCommand(sql, NewCon);
dataread = newconn.ExecuteNonQuery();
NewCon.Close();
return dataread;
}
catch (Exception ex) { MessageBox.Show(ex.Message); return dataread; }
}
}
}
Related
i created a login page, and in its database i crated a column (role) which contains an int value ( 0 or 1 ) to determine the role of the user if it is admin or normal user..
so, i want to write a query that retrieve the int value (role) of the login user and compare it with 1 or 0 to redirect the user to its specific page..
this is my code :
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class LogInPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(TextBox1.Text))
{ Label4.Text = "**Required**"; }
else
{ Label4.Text = ""; }
if (string.IsNullOrWhiteSpace(TextBox2.Text))
{ Label6.Text = "**Required**"; }
else
{ Label6.Text = ""; }
if (TextBox1.Text.Count() > 0 && TextBox2.Text.Count() > 0)
{
SqlConnection con = new SqlConnection(#"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Azooz_2\Documents\Visual Studio 2013\WebSites\Gulf_K\App_Data\DatabaseGulf.mdf;Integrated Security=True;");
SqlDataAdapter sda = new SqlDataAdapter("Select count(*) From Users Where UserName ='" + TextBox1.Text + "' and Password ='" + TextBox2.Text + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
if (){
Response.Redirect("TheArrivalTime.aspx");
}
else{Response.Redirect("TheArrival.aspx")}
}
else
{
Label5.Text = "Wrong UserName or Password !!";
Label6.Text = " ";
Label4.Text = " ";
TextBox1.Text = " ";
TextBox2.Text = " ";
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Label4.Text = " ";
Label5.Text = " ";
Label6.Text = " ";
TextBox1.Text = " ";
TextBox2.Text = " ";
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{this.resetLbls();}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{this.resetLbls();}
protected void resetLbls()
{
Label4.Text = " ";
Label5.Text = " ";
Label6.Text = " ";
}
}
and i want to put the query in this if statement :
if (){
Response.Redirect("TheArrivalTime.aspx");
}
else{ Response.Redirect("TheArrival.aspx");}
so, can anyone help me please ??
why don't select user_type from users where username = variable and
password
= variable and then put [user type field] in the condition if there is a match
... count will only give you a number
When I use Microsoft C# windows forms application. I tried to run the login program then when I clicked the login button. it displays "Logged in as : (name of user)". then in the next form show I didn't see my name on the other form even I use some codes for the passing parameters like
Form1(codes)
public partial class Form1 : Form
{
string namesl;
OleDbCommand cm;
OleDbConnection cn;
OleDbDataReader dr;
string connection = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\10watts.accdb";
public Form1( )
{
cn = new OleDbConnection(connection);
cn.Open();
InitializeComponent();
}
public void getName(string _getName)
{
_getName = dr.GetValue(2).ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox2.PasswordChar = '*';
cn = new OleDbConnection(connection);
cn.Open();
progressBar1.Visible = false;
}
private void btnLog_Click(object sender, EventArgs e)
{
if (textBox1.Text == String.Empty || textBox2.Text == String.Empty)
{
MessageBox.Show("Missing Requirement Field!", "Unable to Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
timer1.Start();
progressBar1.Visible = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Value = progressBar1.Value + 5;
lblPercent.Text = progressBar1.Value + "%";
if (progressBar1.Value == 100)
{
timer1.Enabled = false;
string sql = #"Select * from tblUser where Username like '" + textBox1.Text + "'and Password like '" + textBox2.Text + "'";
cm = new OleDbCommand(sql, cn);
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
MessageBox.Show("Entered Logged In as : " + dr.GetValue(2).ToString(),"Successfully Logged in",MessageBoxButtons.OK,MessageBoxIcon.Information);
_getName = dr.getValue(2).toString();
Form2 frm2 = new Form2(this);
frm2.Show();
}
else
{
}
}
else
{
}
}
}
Form 2
public partial class Form2 : Form
{
OleDbCommand cmd;
OleDbConnection cn;
OleDbDataReader dr;
public string names;
string connection = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\10watts.accdb";
public Form2( )
{
cn = new OleDbConnection(connection);
cn.Open();
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.loggedinform.getName(names);//this thing i worried about :/
}
This whole code that I tried when I was using c# application.
Need your opinions or codes that may use for passing parameters :)
i am creating a one withdarw window my database connection code is right and its display result on same form correctly i want to show the result on next form .
i am implemeted code for that .give me error " inaccessible due to protection level " i search many code but not got any solutions .
this give on this line error " rece.Default.lblbal.Text = balance;".
this my code :
namespace ATMManagementSystem
{
public partial class cust_cash_with_sav : Form
{
public cust_cash_with_sav()
{
InitializeComponent();
}
#region Default Instance
public static cust_cash_with_sav defaultInstance;
/// <summary>
/// Added by the VB.Net to C# Converter to support default instance behavour in C#
/// </summary>
public static cust_cash_with_sav Default
{
get
{
if (defaultInstance == null)
{
defaultInstance = new cust_cash_with_sav();
defaultInstance.FormClosed += new
FormClosedEventHandler(defaultInstance_FormClosed);
}
return defaultInstance;
}
}
static void defaultInstance_FormClosed(object sender,
FormClosedEventArgs e)
{
defaultInstance = null;
}
#endregion
SqlConnection con = new SqlConnection("Data Source=VAIO;Initial
Catalog=ATM;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da;
DataSet ds;
int num1;
int num2;
int total1;
string balance;
public void button1_Click(object sender, EventArgs e)
{
string sql = default(string);
DataTable Log_in = new DataTable();
try
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM user_transaction
where pin_number = " + textBox2.Text + "", con);
cmd.Connection = con;
//da.SelectCommand = cmd;
da = new SqlDataAdapter(cmd);
da.Fill(Log_in);
if (Log_in.Rows.Count > 0)
{
balance = (string)(Log_in.Rows[0]["Total"].ToString());
num1 = int.Parse(balance);
num2 = int.Parse(textBox1.Text);
if (num2 > 25000)
{
MessageBox.Show("You can Only Withdraw Php 25,000");
}
else if (num2 < 200)
{
MessageBox.Show(" Mininum withdrawal is 200");
}
else if (num1 < num2)
{
MessageBox.Show(" Insuffiecient balance");
}
else
{
total1 = num1 - num2;
rece.Default.Show();
rece.Default.lblbal.Text = balance;
rece.Default.lbldep.Hide();
rece.Default.lblwith.Text = num2.ToString();
rece.Default.lblnewbal.Text = total1.ToString();
rece.Default.lblbal.Show();
rece.Default.lbldep.Hide();
rece.Default.lblwith.Show();
rece.Default.lblnewbal.Show();
//MsgBox("success")
rece.Default.lblname.Text =
Mainmenu.Default.lblname.Text;
label2.Text = total1.ToString();
//this.Hide();
}
}
else
{
}
}
catch (Exception)
{
// MessageBox.Show(" Pls. Enter Ammount!");
//MsgBox(ex.Message)
}
textBox1.Text = "";
}
}
}
You can try this
//In Form1's
using(rece form2 = new rece())
{
form2.TheValue = someControlOnForm1.Text;
}
And...
//In rece form
//Create a public property to serve the value
public string TheValue
{
set { lblbal.Text = value;}
}
I want to insert users in mysql without duplicate values at the field "User" .how to show a message to the user when he writes a "User" already exist in the table before he complete the rest of the fields and before he clicks on the button Login?
public void Registrar() throws SQLException {
Connection con = null;
ResultSet rs = null;
Statement st = null;
String user;
String pass;
String pass2;
String email;
String country;
user = jTextField1.getText();
pass = jPasswordField1.getText();
pass2 = jPasswordField2.getText();
email = jTextField2.getText();
country = jComboBox1.getSelectedItem().toString();
if (user.isEmpty()) {
jLabel8.setText("Please enter an Username");
} else if (pass.isEmpty()) {
jLabel8.setText("Please enter an password");
} else if (pass2.isEmpty()) {
jLabel8.setText("please you must confirm your password");
} else if (!pass2.equals(pass)) {
jLabel8.setText("passwords do not match");
} else if (email.isEmpty()) {
jLabel8.setText("Please enter an valid email");
} else if (country.equals("Choose your country")) {
jLabel8.setText("Please choose a Country");
} else {
String sql = "INSERT INTO usuarios(User,Pass,Email,Country) "
+ "VALUES('" + user + "','" + pass + "','" + email + "','" + country + "')";
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/whichmovie", "Asis", "dekrayat24");
System.out.println("Conectado a la base de datos SQLite");
PreparedStatement pstm = con.prepareStatement(sql);
pstm.execute();
pstm.close();
JOptionPane.showMessageDialog(rootPane, "Congratulations you have created your account");
dispose();
Login l = new Login(null, rootPaneCheckingEnabled);
l.setVisible(true);
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "An error has occurred ,please try later");
}
}
}
I have two functions that have queries that return shipping areas. One returns a pilots certified areas and the other returns areas between point A and B. I want to compare them and select the check boxes of the matching areas. Here is what I have.
private void getAreaText(string PilotID)
{
SqlConnection sqlCN;
SqlCommand sqlCOM;
SqlDataReader sqlDR;
DateTime dato;
string strCOM = ConfigurationManager.AppSettings["database"];
sqlCN = new SqlConnection(strCOM);
try
{
sqlCN.Open();
sqlCOM = new SqlCommand("select f_AreaText, f_DateOfIssue from v_GetAreaText where f_PilotID='" + PilotID + "'", sqlCN);
sqlDR = sqlCOM.ExecuteReader();
CheckBoxList1.Items.Clear();
while (sqlDR.Read())
{
dato = sqlDR.GetDateTime(1);
dato = dato.AddYears(1);
if (DateTime.Now < dato)
CheckBoxList1.Items.Add(sqlDR.GetString(0));
if (CheckBoxList1.Items.Contains(findAreas(Session["PilotID"].ToString)))
{
CheckBoxList1.Items[i].Selected = true;
}
}
sqlDR.Close();
}
catch (DataException ex)
{
Response.Write(ex.ToString());
}
finally
{
sqlCN.Close();
sqlDR = null;
sqlCOM = null;
sqlCN = null;
}
return;
}
protected void findAreas(string PilotID)
{
SqlConnection sqlCN;
SqlCommand sqlCOM;
SqlDataReader sqlDR;
string strCOM = ConfigurationManager.AppSettings["database"];
sqlCN = new SqlConnection(strCOM);
try
{
sqlCN.Open();
sqlCOM = new SqlCommand("select DISTINCT f_AreaText from v_FindAreas where f_PilotID='" + PilotID + "'and f_SailedFrom='" + getLMFromList(FromList) + "'and f_SailedTo='" + getLMFromList(ToList) + "'", sqlCN);
sqlDR = sqlCOM.ExecuteReader();
CheckBoxList1.Items.Clear();
while (sqlDR.Read())
{
CheckBoxList1.Items.Add(sqlDR.GetString(0));
}
sqlDR.Close();
}
catch (DataException ex)
{
Response.Write(ex.ToString());
}
finally
{
sqlCN.Close();
sqlDR = null;
sqlCOM = null;
sqlCN = null;
}
return;
}
Your code is quite confusing so here is an attempt to organize it a little and make it work at the same time. There's a lot more you could do to improve it but since I'm coding in the dark, I haven't changed it too much. The main thing I've changed is to use SQL parameters instead of concatenating values into a literal command.
private void getAreaText(string PilotID)
{
var strCOM = ConfigurationManager.AppSettings["database"];
var sqlCN = new SqlConnection(strCOM);
try
{
sqlCN.Open();
var sqlCOM = new SqlCommand("select f_AreaText, f_DateOfIssue from v_GetAreaText where f_PilotID=#p1", sqlCN);
sqlCOM.Parameters.AddWithValue("#p1", PilotID);
var sqlDR = sqlCOM.ExecuteReader();
CheckBoxList1.Items.Clear();
while (sqlDR.Read())
{
var dato = sqlDR.GetDateTime(1);
dato = dato.AddYears(1);
if (DateTime.Now < dato)
{
var AreaText = sqlDR.GetString(0);
CheckBoxList1.Items.Add(AreaText);
if (findAreas(PilotID, AreaText))
// Do you want Selected here or Checked ?
CheckBoxList1.Items[CheckBoxList1.Count-1].Selected = true;
}
}
}
catch (DataException ex)
{
Response.Write(ex.ToString());
}
finally
{
sqlDR.Close();
sqlCN.Close();
sqlDR = null;
sqlCOM = null;
sqlCN = null;
}
return;
}
protected bool findAreas(string PilotID, string AreaText)
{
var strCOM = ConfigurationManager.AppSettings["database"];
var sqlCN = new SqlConnection(strCOM);
try
{
sqlCN.Open();
sqlCOM = new SqlCommand("select DISTINCT f_AreaText from v_FindAreas where f_PilotID=#p1 and f_SailedFrom=#p2 and f_SailedTo=#p3 and f_AreaText=#p4", sqlCN);
sqlCOM.Parameters.AddWithValue("#p1", PilotID);
sqlCOM.Parameters.AddWithValue("#p2", getLMFromList(FromList));
sqlCOM.Parameters.AddWithValue("#p3", getLMFromList(ToList));
sqlCOM.Parameters.AddWithValue("#p4", AreaText);
var sqlDR = sqlCOM.ExecuteReader();
if (sqlDR.HasRows)
return true;
}
catch (DataException ex)
{
Response.Write(ex.ToString());
}
finally
{
sqlDR.Close();
sqlCN.Close();
sqlDR = null;
sqlCOM = null;
sqlCN = null;
}
return false;
}