TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Md. Sinin
NA
2
4k
System.InvalidCastException: 'Specified cast is not valid
Oct 21 2018 1:12 PM
I want to make a system where i can show data from two table with two combobox but when i am about to complete i have shown this exception and i cann't solve this so please help me here is my full code..
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
using
Oracle.DataAccess.Client;
namespace
combobox
{
public
partial
class
Form1 : Form
{
List movies =
new
List();
List catagories =
new
List();
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
string
connection =
"Data Source = (DESCRIPTION = "
+
"(ADDRESS = (PROTOCOL = TCP)(HOST = Mihadul)(PORT = 1521))"
+
"(CONNECT_DATA ="
+
"(SERVER = DEDICATED)"
+
"(SERVICE_NAME = tick)"
+
")"
+
");User ID=mihadul;Password=mihadul123;"
;
OracleConnection con =
new
OracleConnection(connection);
con.Open();
OracleCommand cmdcat =
new
OracleCommand(
"SELECT * FROM CATOGORY"
, con);
OracleDataReader dr = cmdcat.ExecuteReader();
while
(dr.Read())
{
cmb_catlist.Items.Add(dr[
"CAT_NAME"
]);
catagories.Add(
new
Category()
{
cat_id = ((
int
)dr[
"cat_id"
]),
cat_name = dr[
"cat_name"
]
as
string
});
}
con.Close();
con.Open();
OracleCommand cmdmovie =
new
OracleCommand(
"SELECT * FROM MOVIES"
, con);
OracleDataReader dr1 = cmdmovie.ExecuteReader();
while
(dr1.Read())
{
movies.Add(
new
Movie()
{
id = ((
int
)dr1[
"id"
]),
movie_name = dr1[
"movie_name"
]
as
string
,
cat_id = ((
int
)dr1[
"cat_id"
])
});
}
con.Close();
}
private
string
[] GetMovieById(
int
id)
{
return
movies.Where(line => line.cat_id == id).Select(l => l.movie_name).ToArray();
}
private
void
cmb_catlist_SelectedIndexChanged(
object
sender, EventArgs e)
{
cmb_movlist.Items.Clear();
int
id = catagories[cmb_catlist.SelectedIndex].cat_id;
foreach
(
string
name
in
GetMovieById(id))
{
this
.cmb_movlist.Items.Add(name);
}
}
}
[Serializable]
class
Category
{
public
int
cat_id {
get
;
set
; }
public
string
cat_name {
get
;
set
; }
}
[Serializable]
class
Movie
{
public
int
id {
get
;
set
; }
public
string
movie_name {
get
;
set
; }
public
int
cat_id {
get
;
set
; }
}
}
Reply
Answers (
1
)
How to access a Datatable value from a class to form
I wont to open a new form but i found a error