private void startSearch_Click(object sender, EventArgs e)
{
try
{
DB db = new DB();
DataTable table = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter();
MySqlCommand command = new MySqlCommand("SELECT * FROM `users` WHERE `ID` = @IDUser OR `login` LIKE @loginSearch", db.getConnection());
command.Parameters.AddWithValue("IDUser", int.TryParse(txtSearch.Text, out int IDuser));
command.Parameters.AddWithValue("loginSearch", string.Format("%{}%", txtSearch.Text));
adapter.SelectCommand = command;
adapter.Fill(table);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Такого пользователя нет!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void txtSearch_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
startSearch.PerformClick();
}
}
текст ошибки
System.FormatException: Input string was not in a correct format. Failure to parse near offset 2. Expected an ASCII digit.
at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
at System.String.Format(String format, Object arg0)
at KR_Michalev.AdminPanel.startSearch_Click(Object sender, EventArgs e) in C:\Users\wekol\Documents\GitHub\Register-Autorization-ClearMainMenu\AdminPanel.cs:line 44
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at KR_Michalev.AdminPanel.txtSearch_KeyPress(Object sender, KeyPressEventArgs e) in C:\Users\wekol\Documents\GitHub\Register-Autorization-ClearMainMenu\AdminPanel.cs:line 53
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)