这是我的C#代码:
public ReportForm(string type,string param1,string param2,string param3,string param4,string param5)
{
cn.ConnectionString = @"Data Source=.\SQLExpressAttachDbFilename=|DataDirectory|Tourism.mdf;Persist Security Info=True;User ID=sa;Password=xxxxxxx";
cn.Open();
cm.Connection = cn;
if (type == "OmraGroup")
{
string sql = "SELECT * from Clients where OmraGroupID='" + param1 + "'";
DataSet1 ds = new DataSet1();
SqlDataAdapter sda = new SqlDataAdapter(sql, cn);
sda.Fill(ds.Tables["Clients"]);
OmraReport v = new OmraReport();
v.SetDataSource(ds.Tables["Clients"]);
crystalReportViewer1.ReportSource = v;
crystalReportViewer1.Refresh();
}
}
它在前一行之前的行中给出了异常object reference not set to an instance of an object
。它和我一样多年来一直很有魅力,当我再次使用那段代码时,它突然给了我这个例外。出了什么问题?
这里是堆栈跟踪
TourismCo.exe!TourismCo.Reporting.ReportForm.ReportForm(string type,string param1,string param2,string param3,string param4,string param5)Line 34 C# TourismCo.exe!TourismCo.FrontEnd.Religional.Omra.button10_Click(object sender,System.EventArgs e)第151行+ 0x124字节C# System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e)+ 0x65 bytes
System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent)+ 0x113 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m,System.Windows.Forms.MouseButtons button,int clicks)+ 0x3e7 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)+ 0xd39 bytes System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m)+ 0x1da bytes
System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m)+ 0x24 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)+ 0x46 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd,int msg,System.IntPtr wparam,System.IntPtr lparam)+ 0xad bytes [原产于管理过渡]
[管理到原生过渡]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID,int reason,int pvLoopData)+ 0x5c3 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason,System.Windows.Forms.ApplicationContext context)+ 0x578 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason,System.Windows.Forms.ApplicationContext context)+ 0x65 bytes
TourismCo.exe!TourismCo.Program.Main()第17行+ 0x28字节C# [原产于管理过渡]
[管理到原生过渡]
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()+ 0x47 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext,System.Threading.ContextCallback callback,object state)+ 0x9b bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()+ 0x4d bytes