|
I am using this code but getting "Object reference not set to an instance of an object.".
This is the code and below it is the error message:
private void generate_report()
{
npg_connection = new NpgsqlConnection("Server=www.db.2connectbahrain.com;Port=5432;User Id=jassim_rahma;Password=731004167;Database=billing;");
npg_connection.Open();
// npg_command.CommandText = "Select category_title FROM reports_category ORDER BY category_title";
npg_command.CommandText = "select * from cdr where local_gateway_start_dt between '2006-08-01 00:00:00' and '2006-08-01 23:59:59' and originator_ip = '80.88.247.115' and dest_reg_id = '2connect_pbx' and called_num_e164 in('16500110', '16500199') and error_description != ''";
npg_command.Connection = npg_connection;
MessageBox.Show(npg_command.CommandText);
npg_command.Connection.Open();
npg_reader = npg_command.ExecuteReader();
while (npg_reader.Read())
{
MessageBox.Show(npg_reader.GetValue(0).ToString());
}
npg_command.Connection.Close();
}
and here s the error message:
System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="CDR Report" StackTrace: at CDR_Report.main_form.generate_report() in C:\Documents and Settings\jassim\My Documents\Visual Studio 2005\Projects\CDR Report\CDR Report\main_form.cs:line 31 at CDR_Report.main_form.btnGenerate_Click(Object sender, EventArgs e) in C:\Documents and Settings\jassim\My Documents\Visual Studio 2005\Projects\CDR Report\CDR Report\main_form.cs:line 58 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at CDR_Report.Program.Main() in C:\Documents and Settings\jassim\My Documents\Visual Studio 2005\Projects\CDR Report\CDR Report\Program.cs:line 17 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
Jassim Rahma |