using (SqlConnection sqlConn = new SqlConnection("Data Source=TANYA-PC;Initial Catalog=biore1;Integrated Security=True")) //here goes connStrng or the variable of it
{
sqlConn.Open();
string sqlQuery = @"SELECT farmername,villagename,gender,farmsize FROM cottonpurchase WHERE farmercode = @code";
using (SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn))
{
cmd.Parameters.Add("@code", SqlDbType.Int).Value = intValue;
using (SqlDataReader reader = cmd.ExecuteReader())
{;
if (reader.Read())
{
TxtFarmerName.Text = (string)reader[0];
TxtVillageName.Text = (string)reader[1];
TxtGender.Text = (string)reader[2];
}
else
MessageBox.Show("For Farmer Code " + intValue.ToString() + " there is no farmer in the database.");
}
}
}
Senin, 26 Februari 2018
Using - End Using connection
How to pass data from 2nd activity to 1st activity when pressed back? - android
I've 2 activities, Activity1 and Activity2.
In
Activity1 I've a Button and TextView. When the button is clicked Activity2 is started.
In
Activity2 I've an EditText.
I want to display the data retrieved from EditText in Activity2 in the TextView in Activity1 when back is pressed from Activity2.
can someone help me with the code to make this work?
Answer :
Start Activity2 with
startActivityForResult and use setResult method for sending data back from Activity2 to Activity1. In Activity1 you will need to override onActivityResult for updating TextView with EditText data from Activity2.
For example:
In Activity1, start Activity2 as:
Intent i = new Intent(this, Activity2.class);
startActivityForResult(i, 1);
In Activity2, use
setResult for sending data back:Intent intent = new Intent();
intent.putExtra("editTextValue", "value_here")
setResult(RESULT_OK, intent);
finish();
And in Activity1, receive data with
onActivityResult:public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if(resultCode == RESULT_OK) {
String strEditText = data.getStringExtra("editTextValue");
}
}
}
If you can, also use SharedPreferences for sharing data between Activities.
Source : https://stackoverflow.com/questions/14292398/how-to-pass-data-from-2nd-activity-to-1st-activity-when-pressed-back-android
Label:
android,
C#,
xamarin,
xamarin:android
How to set a button at a fixed location on the bottom of UI using Xamarin Forms?
A
FrameLayouts purpose is to overlay things on top of each other. This is not what you want.
In your
RelativeLayout example you set the ListViews height and width to MATCH_PARENT this is going to make it take up the same amount of space as its parent, and thus take up all of the space on the page (and covers the button).
Try something like:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
The
layout_weight dictates how the extra space is to be used. The Button does not want to stretch beyond the space it requires, so it has a weight of 0. The ListView wants to take up all of the extra space, so it has a weight of 1.
You could accomplish something similar using a
RelativeLayout, but if it is just these two items then I think a LinearLayout is simpler.
Source : https://stackoverflow.com/questions/4936553/android-how-can-you-align-a-button-at-the-bottom-and-listview-above
Label:
android,
C#,
xamarin,
xamarin:android
Langganan:
Komentar (Atom)

