Answer the question
In order to leave comments, you need to log in
Cannot convert from string to int. But all data is string. Why?
The program opens a connection to the database, takes a data of type nvarchar (50) from there and writes them to string, but writes that it cannot be converted from string to int.
private async void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Project\SaveMePassword\SaveMePassword\Database1.mdf;Integrated Security=True";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd;
cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM [Data] WHERE NameSite='" + listBox1.Text + "';";
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
// Загружаем данные
while (sdr.Read())
{
// Здесь ошибка
______________________________________
string sSite = sdr.GetString("Site");
string sUser = sdr.GetString("User");
string sPassworSite = sdr.GetString("PasswordSite");
________________________________________
_BoxSite.Text = sSite;
_BoxLogin.Text = sUser;
_BoxPassword.Text = sPassworSite;
}
// Закрываем соединение
con.Close();
}
catch (Exception)
{
MessageBox.Show("Ошибка");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question