Click here to Skip to main content
16,005,178 members
Home / Discussions / C#
   

C#

 
AnswerRe: Go to a specified node in treeview Pin
DaveyM6922-Aug-08 21:31
professionalDaveyM6922-Aug-08 21:31 
GeneralRe: Go to a specified node in treeview Pin
Abdul Rahman Hamidy22-Aug-08 23:22
Abdul Rahman Hamidy22-Aug-08 23:22 
AnswerRe: Go to a specified node in treeview Pin
Kevin Marois23-Aug-08 7:08
professionalKevin Marois23-Aug-08 7:08 
QuestionLockbits error [modified] Pin
gigahertz20522-Aug-08 18:04
gigahertz20522-Aug-08 18:04 
AnswerRe: Lockbits error Pin
Paul Conrad22-Aug-08 18:15
professionalPaul Conrad22-Aug-08 18:15 
GeneralRe: Lockbits error Pin
gigahertz20522-Aug-08 18:38
gigahertz20522-Aug-08 18:38 
GeneralRe: Lockbits error Pin
Paul Conrad22-Aug-08 19:06
professionalPaul Conrad22-Aug-08 19:06 
QuestionUnable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Jassim Rahma22-Aug-08 14:21
Jassim Rahma22-Aug-08 14:21 
I am using the code below to view list of car brands below car makes but while loading i get the above error and i guess it's because the car make value is null during loading. I tried to use if (cboVehicleMake.SelectedItem == null) but still getting the same error.


what can i do?




using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.SqlClient;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;



namespace Rent_A_Car

{

public partial class frmMain : Form

{

SqlConnection sql_connection = null;

SqlCommand sql_command = null;

SqlDataAdapter sql_adapter;

// DataTable data_table = null;

SqlDataReader sql_reader = null;

DataSet data_set = null;



public frmMain()

{

InitializeComponent();

}



private void hide_panels()

{

panelVehicles.Visible = false;

panelVehicleDetails.Visible = false;

}



private void get_vehicle_makes()

{

try

{

sql_connection = new SqlConnection("Data Source=.\\SQLEXPRESS;initial catalog=rent_a_car_company;integrated security=true;");

sql_connection.Open();



sql_command = new SqlCommand("sp_get_vehicle_makes", sql_connection);

sql_command.CommandType = CommandType.StoredProcedure;



// Create data adapter object

sql_adapter = new SqlDataAdapter();

sql_adapter.SelectCommand = sql_command;



// Create a dataset object and fill with data using data adapter's Fill method

data_set = new DataSet();

sql_adapter.Fill(data_set, "vehicle_makes");



// Attach dataset's DefaultView to the combobox

cboVehicleMake.DataSource = data_set.Tables["vehicle_makes"].DefaultView;

cboVehicleMake.DisplayMember = "vehicle_make";

cboVehicleMake.ValueMember = "vehicle_make_id";



cboVehicleMake.SelectedValue = -1;

}

// catch (Exception oE)

// {

// MessageBox.Show("Problem Populating Reader Box: [" + oE.ToString() + "]");

// }

finally

{

if (sql_reader != null) sql_reader.Close();

// if (sql_connection != null)

// {

// if (sql_connection.State == ConnectionState.Open)

// sql_connection.Close();

// }

}

}



private void get_vehicle_brands_by_make()

{

try

{

sql_connection = new SqlConnection("Data Source=.\\SQLEXPRESS;initial catalog=rent_a_car_company;integrated security=true;");

sql_connection.Open();



sql_command = new SqlCommand("sp_get_vehicle_brands_by_make", sql_connection);

sql_command.CommandType = CommandType.StoredProcedure;

sql_command.Parameters.Add("@vehicle_make", SqlDbType.Int).Value = Convert.ToInt32(cboVehicleMake.SelectedValue);



// Create data adapter object

sql_adapter = new SqlDataAdapter();

sql_adapter.SelectCommand = sql_command;



// Create a dataset object and fill with data using data adapter's Fill method

data_set = new DataSet();

sql_adapter.Fill(data_set, "vehicle_brands");



// Attach dataset's DefaultView to the combobox

cboVehicleBrands.DataSource = data_set.Tables["vehicle_brands"].DefaultView;

cboVehicleBrands.DisplayMember = "vehicle_brand";

cboVehicleBrands.ValueMember = "vehicle_brand_id";



cboVehicleBrands.SelectedValue = -1;

}

// catch (Exception oE)

// {

// MessageBox.Show("Problem Populating Reader Box: [" + oE.ToString() + "]");

// }

finally

{

if (sql_reader != null) sql_reader.Close();

// if (sql_connection != null)

// {

// if (sql_connection.State == ConnectionState.Open)

// sql_connection.Close();

// }

}

}



private void toolExit_Click(object sender, EventArgs e)

{

Application.Exit();

}



private void frmMain_Load(object sender, EventArgs e)

{



}



private void navNewVehicle_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)

{

if (panelVehicleDetails.Visible != true)

{

// hide all panels;

hide_panels();



get_vehicle_makes();





// panelVehicleDetails.Width = 635;

// panelVehicleDetails.Height = 435;

// panelVehicleDetails.Top = 200;

// panelVehicleDetails.Left = 52;

panelVehicleDetails.Location = new System.Drawing.Point(navMain.Width + 5, navMain.Top);

panelVehicleDetails.Size = new Size(this.Width - navMain.Width - 40, navMain.Height);

panelVehicleDetails.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;

panelVehicleDetails.Visible = true;



/*

Control control_name = panelVehicleDetails;

control_name.Name = "panelVehicleDetails";

control_name.Width = 635;

control_name.Height = 435;

control_name.Top = 200;

control_name.Left = 52;

* */

}

}



private void navOurVehicles_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)

{

hide_panels();

}



private void cboVehicleMake_SelectedIndexChanged(object sender, EventArgs e)

{

if (cboVehicleMake.SelectedItem == null)

{

return;

}

else

{

get_vehicle_brands_by_make();

}

}

}

}
AnswerRe: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Christian Graus22-Aug-08 15:37
protectorChristian Graus22-Aug-08 15:37 
GeneralRe: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Jassim Rahma23-Aug-08 4:43
Jassim Rahma23-Aug-08 4:43 
Questionsql output to form Pin
Jassim Rahma22-Aug-08 12:18
Jassim Rahma22-Aug-08 12:18 
AnswerRe: sql output to form Pin
PIEBALDconsult22-Aug-08 12:56
mvePIEBALDconsult22-Aug-08 12:56 
GeneralRe: sql output to form Pin
Jassim Rahma22-Aug-08 13:38
Jassim Rahma22-Aug-08 13:38 
GeneralRe: sql output to form Pin
Paul Conrad22-Aug-08 19:38
professionalPaul Conrad22-Aug-08 19:38 
GeneralRe: sql output to form Pin
PIEBALDconsult23-Aug-08 4:15
mvePIEBALDconsult23-Aug-08 4:15 
AnswerRe: sql output to form Pin
Paul Conrad22-Aug-08 19:37
professionalPaul Conrad22-Aug-08 19:37 
QuestionHow To Set Toolbar Button Images Pin
Kevin Marois22-Aug-08 8:46
professionalKevin Marois22-Aug-08 8:46 
AnswerRe: How To Set Toolbar Button Images Pin
Mark Salsbery22-Aug-08 9:55
Mark Salsbery22-Aug-08 9:55 
GeneralRe: How To Set Toolbar Button Images [modified] Pin
Kevin Marois22-Aug-08 10:57
professionalKevin Marois22-Aug-08 10:57 
QuestionExcel 2007 Add-in ??? Pin
Member 426807222-Aug-08 8:02
Member 426807222-Aug-08 8:02 
QuestionCustom property with multiple values in property grid Pin
DaveyM6922-Aug-08 8:00
professionalDaveyM6922-Aug-08 8:00 
AnswerRe: Custom property with multiple values in property grid [Solved] Pin
DaveyM6922-Aug-08 10:11
professionalDaveyM6922-Aug-08 10:11 
QuestionCan We Use Windows Presentation Foundation in .Net framework 2.0? Pin
bruze22-Aug-08 6:49
bruze22-Aug-08 6:49 
AnswerRe: Can We Use Windows Presentation Foundation in .Net framework 2.0? Pin
Paul Conrad22-Aug-08 6:52
professionalPaul Conrad22-Aug-08 6:52 
AnswerRe: Can We Use Windows Presentation Foundation in .Net framework 2.0? Pin
DaveyM6922-Aug-08 8:23
professionalDaveyM6922-Aug-08 8:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.