|
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();
}
}
}
}
|
|
|
|
|
1 - don't post so much code
2 - tell us what line your code crashes on
3 - use the debugger to see what object is causing the crash, and give us more info that way, too
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
the line causing the problem is this:
sql_command.Parameters.Add("@vehicle_make", SqlDbType.Int).Value = Convert.ToInt32(cboVehicleMake.SelectedValue);
i guess because during the combobox creation it's still filling the values so it will find null value in the vehicle make but i don't know why thought i am populating the vehicle makes first?!
|
|
|
|
|
i am developing a desktop windows for application but i don't want to include the sql management express with the application therefore i want some way to do my sql statement (in case of troubleshooting) and i want to that from the same application (via admin user)
so if i place a textbox to enter the sql statements how can i view the output?
|
|
|
|
|
|
what about multip statments like in sql management express i can do this:
select * from company;
select * from employee?
how about errors output?
|
|
|
|
|
Have separate panels for them or something like that.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
A TabControl with a TabPage for each result set.
When I get messages I put them in a DataTable and treat them the same.
|
|
|
|
|
I second using datagridview as suggested.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I have dragged a toolbar off the toolbox onto my winform. I then opened the Buttons collection and added a button.
I can't for the life of me figure out how to set the button's image.
Everything makes sense in someone's mind
|
|
|
|
|
KMAROIS wrote: I then opened the Buttons collection and added a button
Are you doing this at runtime or in the designer?
What about the DisplayStyle and Image properties
(assuming ToolStripButton class)?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have figured it out. Thanks
Everything makes sense in someone's mind
modified on Friday, August 22, 2008 5:05 PM
|
|
|
|
|
Hello,
I would like to write a function in VS2008 C# that I can use in Excel2008.
I tried with this template that is available in VS2008 TeamSystem called "Excel 2007 Add-in" - when I write some code in this provided "ThisAddIn_Startup" function it works - but I would need to write my own function (e.g. something like: public int AddMe( int a, int b ) { return a+b; } ) which is accessible from within an excel cell like =AddMe(3,4).
Any help would be highly appreciated
regards, Dussel
|
|
|
|
|
I have a class that has a property that is a struct of two Int64s. Similar to the Size property which is two Int32s if that explains it better!
How can I get this to be usable in the property grid?
At the moment, as a workaround, I've made this property private and created another public property of type string and used the struct's ToString and TryParse methods in the getter and setter to alter the original property.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
I figured it out
For anyone that comes across this I needed to:
1. Create a convertor class that derived from ExpandableObjectConverter
2. Override CanConvertTo
3. Override CanConvertFrom
4. Override ConvertTo
5. Override ConvertFrom
6. Apply the TypeConverterAttribute to the property
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi,
Can We Use Windows Presentation Foundation in .Net framework 2.0?
|
|
|
|
|
No. It started in .NET 3.0. Are you trying to use something you created in WPF with something else done in .NET 2.0? That may be possible, but the WPF isn't in 2.0....
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
No but if the reason you're asking is because you're using vs2005 then you can add the extensions. Just google for vs2005 wpf
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi all im trying to convert a .dll call method from VBA to C#
VBA Code look like this:
Public Sub SnodAnrop()
Dim result As String
host = "***"
port = "***"
user = "****"
pass = "**"
cert = ""
cacert = ""
service = "**"
arg = vTyp & pnr & datumIn & datumUt
extra = ""
result = Space(1024)
buf = 1024
i = Module1.snod25x(host, port, user, pass, cert, cacert, service, arg, extra, result, buf)
SnodError (result)
If sFel = 0 Then
result = GVRSvar(result)
WriteToFile (result)
End If
Declare Function snod25x Lib "sn25.dll" Alias "****" (ByVal host As String, _
ByVal port As String, _
ByVal user As String, _
ByVal passwd As String, _
ByVal cert As String, _
ByVal CAert As String, _
ByVal Nodtjanst As String, _
ByVal arg As String, _
ByVal extra As String, _
ByVal result As String, _
ByVal Resultbuf As Long) As Long
And i have come this far in C#:
private string result;
[DllImport("sn25.dll", EntryPoint = "****")]
static extern int snod(string host, string port, string user, string passwd, string cert, string CAert, string Nodtjänst, string arg, string extra, string result, int buf);
private void button1_Click(object sender, EventArgs e)
{
result = new String(' ', 1024);
string user = "*****";
string pass = "***";
string service = "GVRPOSDIAP2";
int i = snod("*****", "****", user, pass, "", "", service, textBox1.Text ,"", result, 1024);
textBox2.Text = i.ToString();
textBox3.Text = result;
}
This two code strips are the same. In different language.
The Problem is that dont get any result back, its empty, but in the identical code in VBA its returning info at string result. My Question is how can i write the code in C# so a get back info at the string result????
The int i is giving me status back witch is 0 that meens OK but no info in return!!
Please Help Me!!
Thanks
|
|
|
|
|
My Fellow Coders,
Good day.
I need to write a .dll that will read and write to Excel and Access. Is there an existing code that I can use? Is there an example of how to do this that is endorsed by microsoft and the .net 3.0/3.5 framework.
I tried an ADO.Net approach but ran into errors and read on msdn that approach is not encouraged.
Any help you can provide would be great.
Thanks in advance.
BP
|
|
|
|
|
BlitzPackage wrote: I need to write a .dll
A .NET assembly? If yes you need to look into the Primary Interop Assembly[^] for each product.
led mike
|
|
|
|
|
Like led mike suggested, look into the Interop Library. I use it on a regular basis for client reporting tools and it is good to have around.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Gentlemen,
Thanks. Does the Primary Interop Assembly come with Visual Studio 2008 Professional?
Thanks again,
BP
|
|
|
|
|
BlitzPackage wrote: Thanks. Does the Primary Interop Assembly come with Visual Studio 2008 Professional?
Ok, uh try this, click on the link I gave in my post, then (and yes, I know this is very unpopular with programmers these days) READ THE ARTICLE.
led mike
|
|
|
|
|
LOL!!!
Hey, have some mercy, I'm new at programming
Thanks for the information. I think that will be what I need.
BP
|
|
|
|