|
Solved. Thanks.
modified 5-Jul-21 11:01am.
|
|
|
|
|
I was just going to say:
"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.
But you should know that by now ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you. It worked. It was my fault. Excuse me.
|
|
|
|
|
No problem!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I want to update an existing XML file in DropBox without uploading and replacing a new file. Is it possible using DropBox API?
|
|
|
|
|
After a quick look at the documentation for the API, found here[^], no, you can't.
|
|
|
|
|
Hi
I want to add Label and Farme controls in a way that Label's text is placed inside the Frame and the Frame size is changed based on text lenght. Actually, I want to add this XAML code by clicking a button:
<StackLayout x:Name="MyStack">
<Frame BackgroundColor="GreenYellow" CornerRadius="5" Padding="5">
<Label Text="Just For Test" FontAttributes="Bold" FontSize="Medium" />
</Frame>
</StackLayout>
between these code:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MReport.TabbedMainPage">
<ContentPage Title="New Report" IconImageSource="NewReport.png" BackgroundImageSource="blue_windows.jpg">
<StackLayout Margin="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollView>
<StackLayout x:Name="MyStack">
</StackLayout>
</ScrollView>
<Button Grid.Row="1" Text="Add New Item" Clicked="Button_Clicked" />
</Grid>
<Button Grid.Row="1" Text="Send" />
</StackLayout>
</ContentPage>
<ContentPage Title="Report History" IconImageSource="History.png" BackgroundImageSource="blue_windows.jpg" />
<ContentPage Title="Messages" IconImageSource="Message.png" BackgroundImageSource="blue_windows.jpg"/>
</TabbedPage>
I tried this:
private async void Button_Clicked(object sender, EventArgs e)
{
MyStack.Children.Add(new Frame { CornerRadius = 5, BackgroundColor = Color.Azure});
MyStack.Children.Add(new Label { Text = time_text[0].ToString() });
MyStack.Children.Add(new Label { Text = time_text[1].ToString(), FontAttributes = FontAttributes.Bold, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)) });
}
But it cannot add text inside the Frame.
Please help me.
modified 1-Jul-21 12:51pm.
|
|
|
|
|
You create the Frame; you add the labels to the Frame; THEN you add the Frame to the StackLayout. (Or maintain a Frame reference.)
You're just adding everything to the StackLayout.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Ok, Solved. Thanks.
modified 1-Jul-21 13:53pm.
|
|
|
|
|
hi, i have a datagridview where i get the Ids and the amount in the first and second column,
but the third column should show me a function code for example compared to the
dataGridView2.Rows [dvd] .Cells [0] .Value
but, it displays them to me at the bottom instead of that evening on the same line
but, it displays them to me at the bottom instead of that evening on the same line
here is the code
void gab2relik()
{
cnx = new SqlConnection(db.RXcon);
try
{
cnx.Open();
}
catch
{
MessageBox.Show("Erreure lors de la Connexion");
}
if (dataGridView2.Rows.Count>0)
{
for (int dvd = 0; dvd < dataGridView2.Rows.Count; dvd++)
{
string ct = "select grade from fction inner join person on person.id= fction.id where id ='" + dataGridView2.Rows[dvd].Cells[0].Value + "'";
commd222 = new SqlCommand(ct);
commd222.Connection = cnx;
try
{
SqlDataReader d = commd222.ExecuteReader();
d.Read();
DataGridViewRow Row = (DataGridViewRow)dataGridView2.Rows[0].Clone();
Row.Cells[2].Value = d["grade"].ToString();
d.Close();
dataGridView2.Rows.Add(Row);
}
catch (Exception tt)
{
MessageBox.Show(tt.Message.ToString());
}
finally
{
}
}
}
modified 1-Jul-21 6:33am.
|
|
|
|
|
remiki wrote:
string ct = "select grade from fction inner join person on person.id= fction.id where id ='" + dataGridView2.Rows[dvd].Cells[0].Value + "'"; Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
Beyond that, you need to update your code to store the value in the expected row, rather than adding a new row at the bottom.
You should also stop storing connections in class-level fields. Instead, create them when they're required, and wrap them in using blocks to ensure they are always disposed of properly.
void gab2relik()
{
if (dataGridView2.Rows.Count == 0) return;
using (var conn = new SqlConnection(db.RXcon))
using (var cmd = new SqlCommand("SELECT grade FROM fction INNER JOIN person ON person.id = fction.id WHERE fction.id = @ID", conn))
{
var pID = cmd.Parameters.Add("@ID", SqlDbType.VarChar);
try
{
conn.Open();
}
catch
{
MessageBox.Show("Erreure lors de la Connexion");
return;
}
foreach (DataGridViewRow row in dataGridView2.Rows)
{
pID.Value = row.Cells[0].Value ?? DBNull.Value;
row.Cells[2].Value = cmd.ExecuteScalar();
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
That's some odd code ... but ...
Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
When you've fixed that through your whole app, start looking at that code.
Why are you reading each grade separately? Just issue one SQL command and read the lot - use a DataAdapter and read it all into a DataTable - then use that data to fill each row.
What you are doing is causing a heck of a lot of work for both your system and the DB Server, and you aren't even checking to see if any matching row exists!
You aren't disposing - or even closing - the connection: put that in a using block and teh system will "tidy up" behind you.
Your finally block is irrelevant, since you don't do anything in it!
And ... why are you adding rows to the DGV that you are using to limit how many times you go round the loop? That will never end until something somewhere fails - and then you will get message box after message box because it's in a try...catch inside the loop!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
I want to write a code like this that runs perfectly in WinForms:
int count = 0;
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Label))
if (((Label)c).BackColor == Color.Red)
count++;
}
But in Xamarin, I cannot use Control class. There is no namespace for it. How can I do the same in Xamarin?
|
|
|
|
|
Your WinForms code would be better written as:
int count = 0;
foreach (Label l in this.Controls.OfType<Label>())
{
if (l.BackColor == Color.Red)
{
count++;
}
} Or simply:
int count = this.Controls.OfType<Label>().Count(l => l.BackColor == Color.Red);
Xamarin forms doesn't have a similar concept. You might be able to do something similar by walking the visual tree - eg:
the urban canuk, eh: VisualTreeHelper for Xamarin.Forms[^]
However, it would almost certainly be better to use MVVM concepts to achieve your goal.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I'm working on Xamarin project. I want to pass a parameter from one page to another.
I used this code for one of pages:
public TabbedMainPage(string parameter)
{
InitializeComponent();
On<Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
On<Android>().SetIsSmoothScrollEnabled(false);
lbl01.Text = parameter;
}
App.xaml.cs:
public App()
{
InitializeComponent();
MainPage = new TabbedMainPage();
}
I have error under
TabbedMainPage in App.xaml.cs
How can I solve that error?
|
|
|
|
|
MainPage = new TabbedMainPage( <parameter> );
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I wrote MainPage = new TabbedMainPage(<parameter>);
But it has error under <parameter>);
|
|
|
|
|
You're supposed to supply your "own" parameter; the <parameter> is a "place holder"; you don't actually enter it.
Why did you define a parameter in your constructor when you don't know how to use it?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I tried it. My parameter name is "parameter". I used MainPage = new TabbedMainPage(parameter);
but it has error under parameter
|
|
|
|
|
Where did you "define" parameter? Since it's a string, you could use a literal; e.g. "xxx". (Don't code "xxx"; it's just an example).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
It would be a good idea to actually say what the error is. That might help people to help you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You have defined your constructor as public TabbedMainPage(string parameter) , so it is expecting a string, which you then post into lbl01.Text . So you need something like:
public App()
{
InitializeComponent();
MainPage = new TabbedMainPage("This is the text that will appear in lbl01");
}
|
|
|
|
|
I solved it.
private async void Button_Clicked(object sender, EventArgs e)
{
var result = await Navigation.ShowPopupAsync(new popup01());
lbl01.Text = result.ToString();
}
|
|
|
|
|
That is a different issue.
|
|
|
|