how to solve this inaccessible due to his protection level error? - sql-server-2008

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;}
}

Related

Could not load type 'Devart.Data.MySql.MySqlDependency' from assembly 'Devart.Data.MySql

When I run my code, there is an error as below:
Could not load type 'Devart.Data.MySql.MySqlDependency' from assembly
'Devart.Data.MySql, Version=8.10.1086.0, Culture=neutral,
PublicKeyToken=09af7300eec23701'.
Which part would cause this problem?
Here is my sample codes...
using Devart.Data.MySql;
public partial class Form1 : Form
{
public string Query = "Select * from tbltransaction";
public MySql.Data.MySqlClient.MySqlConnection cn;
public MySql.Data.MySqlClient.MySqlDataAdapter sqlAdapter;
public DataSet dsdatagrid;
public DataTable dt;
public DataGridView datagrid;
public Form1()
{
InitializeComponent();
Start();
}
string connectionString = "User Id=root;Password=123!##abcD;Host=localhost;Database=kcms1_test;";
void Start()
{
try
{
MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();
MySqlCommand commandDeptEmp = new MySqlCommand("select * from tbltransaction", connection);
//MySqlCommand commandPict = new MySqlCommand("select * from mysqlnet_pictures", connection);
MySqlDependency dependency = new MySqlDependency(commandDeptEmp, 1000);
dependency.AddCommandDependency(commandDeptEmp);
//dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
MySqlDependency.Stop(connectionString);
MySqlDependency.Start(connectionString);
OpenLocalDBConnection();
View_Data();
DataGridView_tbltransaction.DataSource = datagrid.DataSource;
}
catch
{
Stop();
}
finally
{
}
}
void Stop()
{
MySqlDependency.Stop(connectionString);
}
void dependency_OnChange(object sender, MySqlTableChangeEventArgs e)
{
// process changes
View_Data();
DataGridView_tbltransaction.DataSource = datagrid.DataSource;
}
void View_Data()
{
sqlAdapter = new MySql.Data.MySqlClient.MySqlDataAdapter(Query, cn);
dsdatagrid = new DataSet();
sqlAdapter.Fill(dsdatagrid);
dt = new DataTable();
datagrid.DataSource = dsdatagrid.Tables;
}
void OpenLocalDBConnection()
{
cn.ConnectionString = "server=locahost;userid=root;password=123!##abcD;database=kcms1_test";
cn.Open();
}
}

Logged in as : (your name) passed to another form using c# passing parameters

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 :)

Copare function and select items in checkbox list for same items

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;
}

ReverseGeocodeQuery giving error

ReverseGeocodeQuery is giving error
1.in "GeoCoordinate(47.60887, -122.34094); " method must have a return type
2.in "reverseGeocode.GeoCoordinate line " reverseGeocode is a field but its used like a type..
ReverseGeocodeQuery reverseGeocode = new ReverseGeocodeQuery();
reverseGeocode.GeoCoordinate = new GeoCoordinate(47.60887, -122.34094);
reverseGeocode.QueryCompleted += reverseGeocode_QueryCompleted;
reverseGeocode.QueryAsync();
void reverseGeocode_QueryCompleted(objectsender,QueryCompletedEventArgs<IList<MapLocation>> e)
{
MapAddress geoAddress = e.Result[0].Information.Address;
}
i used namespace-- using Microsoft.Phone.Maps.Services;
how to rectify this errors..
GOT THE ANSWER
GeoCoordinateWatcher myLocationWatcher;
private GeoCoordinate MyCoordinate = null;
private async void GetCurrentCoordinate()
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracy = PositionAccuracy.High;
try
{
Geoposition currentPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
_accuracy = currentPosition.Coordinate.Accuracy;
MyCoordinate = new GeoCoordinate(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);
if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
{
MyReverseGeocodeQuery = new ReverseGeocodeQuery();
MyReverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(MyCoordinate.Latitude, MyCoordinate.Longitude);
LongitudeTextBlock.Text = MyCoordinate.Longitude.ToString();
LatitudeTextBlock.Text = MyCoordinate.Latitude.ToString();
MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
MyReverseGeocodeQuery.QueryAsync();
}
}
catch (Exception ex)
{
// ...
}
}
public void ReverseGeocodeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
if (e.Error == null)
{
if (e.Result.Count > 0)
{
MapAddress address = e.Result[0].Information.Address;
labelResults.Text = "Current Location: " + address.City + ", " + address.State;
}
}
}
public void Button_Click(object sender, RoutedEventArgs e)
{
GetCurrentCoordinate();
}

Unable to populate table with data from database

I have problem when trying to fetch the data from database and display in database. I get from user input and store as a search variable. This is how I set up my table:
//I get the user input to perform search
#FXML
public void searchResident(ActionEvent event){
String search=getTb_search().getText();
if(search.equals("")){
Dialogs.showErrorDialog(null, "Please enter something", "Blank fields detected", "");
}else{
setUpSearchTable(search);
}
}
//How I set up my table
public void setUpSearchTable(String search) {
TableColumn rmNameCol = new TableColumn("Name");
rmNameCol.setVisible(true);
rmNameCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<SearchNeedyResidentController, String>, ObservableValue<String>>() {
public ObservableValue<String> call(TableColumn.CellDataFeatures<SearchNeedyResidentController, String> p) {
return p.getValue().searchNameProperty();
}
});
TableColumn rmNricCol = new TableColumn("NRIC");
rmNricCol.setCellValueFactory(new PropertyValueFactory<SearchNeedyResidentController, String>("search_nric"));
rmNricCol.setMinWidth(150);
TableColumn rmPhNoCol = new TableColumn("Phone Number");
rmPhNoCol.setCellValueFactory(new PropertyValueFactory<SearchNeedyResidentController,String>("search_phNo"));
rmPhNoCol.setMinWidth(350);
TableColumn rmIncomeCol = new TableColumn("Income($)");
rmIncomeCol.setCellValueFactory(new PropertyValueFactory<SearchNeedyResidentController, String>("search_income"));
rmIncomeCol.setMinWidth(100);
ResidentManagement.entity.NeedyResidentEntity searchValue= new ResidentManagement.entity.NeedyResidentEntity();
//viewProduct.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table_search.setEditable(false);
table_search.getColumns().addAll(rmNricCol, rmNameCol, rmIncomeCol, rmPhNoCol);
table_search.getItems().setAll(searchValue.searchResident(search));
}
}
//How I populate the table data
public List<SearchNeedyResidentController> searchResident(String search){
List ll = new LinkedList();
try {
DBController db = new DBController();
db.getConnection();
String sql = "SELECT * FROM rm_needyresident WHERE name LIKE '" + search + "%'";
ResultSet rs = null;
// Call readRequest to get the result
rs = db.readRequest(sql);
while (rs.next()) {
String nric=rs.getString("nric");
String name = rs.getString("name");
double income = rs.getDouble("familyIncome");
String incomeStr = new DecimalFormat("##.00").format(income);
String phNo = rs.getString("phNo");
SearchNeedyResidentController row = new SearchNeedyResidentController();
row.setSearchNric(nric);
row.setSearchName(name);
row.setSearchIncome(incomeStr);
row.setSearchPhNo(phNo);
ll.add(row);
}
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
System.out.println("Error SQL!!!");
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
return ll;
}
}
When search button is on click, the table column is displayed. However, it's just show a blank table even though there's matching result. I debug already and I think the error is at the retrieving data in the searchResident method. It's not retriving the data from database. Anybody know what's wrong?
Thanks in advance.
try dis one...
#FXML private void SearchButton()
{
Connection c ;
datamem = FXCollections.observableArrayList();
try
{
c = Dao.getCon();
String SQL =SELECT * FROM `Member`;
ResultSet rs = c.createStatement().executeQuery(SQL);
if(table.getColumns().isEmpty())
{
for(int i=0 ; i<rs.getMetaData().getColumnCount(); i++)
{
final int j = i;
TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i+1));
col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
public ObservableValue<String> call(TableColumn.CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
});
table.getColumns().addAll(col);
}//for
}//if
while(rs.next())
{
ObservableList<String> row = FXCollections.observableArrayList();
for(int i=1 ; i<=rs.getMetaData().getColumnCount(); i++)
{
row.add(rs.getString(i));
}// for
datamem.add(row);
}//while
table.setItems(datamem);
}//try
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Problem in Search Button "+e);
}
}//else
}//else
} //search method