private void MakeConnection()
{
SqlConnection connect = new SqlConnection(ZadanieDBS.Properties.Settings.Default.DBSConnectionString.ToString());
try
{
connect.Open();
SqlCommand command = new SqlCommand();
command.Connection = connect;
command.CommandText = "insert into dbo.transakcia values('" + this.transakcia + "','" + this.date + "'," + this.cena + "," + this.provizia + ");";
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connect.Dispose();
connect.Close();
this.Close();
}
}
do premennych mi nacita hodnoty a vsetky chyby zleho vstupu su osetrene spravne ... ale ked debugujem tak mi vsetko prejde a potom ked sa dostane do catch bloku MakeConnection() tak mi vyhodi tym messageBoxom chybu String or binary file would be truncated. The statement has been terminated.
edit: mozno by to bolo lepsie urobit cez
SqlConnection connect = new SqlConnection(cmd,ZadanieDBS.Properties.Settings.Default.DBSConnectionString.ToString());
a ako cmd bude
string cmd = "insert into dbo.transakcia values('" + this.transakcia + "','" + this.date + "'," + this.cena + "," + this.provizia + ");";
ale tak zda sa mi, ze som to skusal tak ... a skusal som to aj cez toto:
command.Parameters.AddWithValue();
a nefungovalo to