tego sie nie da tak napisac . jesli w bazie nie bedzie filmu a ktos wpisze taki tytul , sypnie sie . ale juz wymyslilem jak to zrobic .trzeba dorobic tylko komunikat
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=X-QYLAQ0KRMB6TB;Initial Catalog=Filmy;Integrated Security=True";
conn.Open();
SqlCommand objSqlCommand = new SqlCommand();
objSqlCommand.Connection = conn;
SqlCommand objSqlCommand1 = new SqlCommand();
objSqlCommand1.Connection = conn;
objSqlCommand.CommandType = CommandType.Text;
objSqlCommand1.CommandType = CommandType.Text;
*ok *objSqlCommand.CommandText = "SELECT tytul FROM filmy where nazwa_zagraniczna_podtytul='Cars' ";
objSqlCommand.CommandText = "SELECT klaser FROM filmy where tytul =@nazwa ";
objSqlCommand1.CommandText = "SELECT numer FROM filmy where tytul = @nazwa1";
*ok *objSqlCommand.CommandText = "SELECT count(*) as ilosc FROM Filmy";
*ok *this.Label1.Text = "Jest w klaserze nr : " + (objSqlCommand.ExecuteScalar()).ToString();
objSqlCommand.Parameters.AddWithValue("nazwa ", TextBox1.Text); //bez spacji przed "
objSqlCommand1.Parameters.AddWithValue("nazwa1 ", TextBox1.Text); //bez spacji przed "
TextBox2.Text = objSqlCommand.ExecuteScalar().ToString();
TextBox3.Text = objSqlCommand1.ExecuteScalar().ToString();
conn.Close();
}
catch (Exception NullReferenceException) { TextBox1.Text = NullReferenceException.Message; }
}