C#报“未处理NullReferenceException” [问题点数:25分,结帖人tf2631]

Bbs1
本版专家分:2
结帖率 96%
Bbs7
本版专家分:23388
Blank
黄花 2011年10月 .NET技术大版内专家分月排行榜第二
Bbs5
本版专家分:2022
Bbs9
本版专家分:58277
版主
Blank
蓝花 2011年11月 .NET技术大版内专家分月排行榜第三
Bbs1
本版专家分:2
用户代码未处理nullReferenceException
我在网站上添加了一个网站访问量的统计功能,但是偶尔会出现"用户代码<em>未处理</em>nullReferenceException"但有的时候又好了,请各位高手帮忙解决一下,不胜感激。
用户代码未处理NullReferenceException
sqlString.AppendFormat("SELECT COUNT(*) FROM CRM_TODOLIST_VIEW WHERE (EXPIRATIONDATE>='0' OR (EXPIRATIONDATE), UC.UserId.ToString());rnhere is the errorrnplease tell me what is wrong here rnthank you
出错!!!急!!未处理NullReferenceException
[code=C#]rnrn public DataRow dr;rnrn public void datBD()rn rn MySqlConnection mysqlcon = new MySqlConnection("Server=localhost;userid=root;password=1234;Database=zhwedo");rn mysqlcon.Open();rn //MySqlCommand mysqlcmd = new MySqlCommand("select uname from sdb_members where uname='" + usname + "' ", mysqlcon);rn string mysqlcmd="select * from sdb_members where uname='" + usname + "'";rn MySqlDataAdapter date = new MySqlDataAdapter(mysqlcmd, mysqlcon);rn DataSet ds = new DataSet();rn date.Fill(ds, "mymuma");rn dr = ds.Tables["mymama"].Rows[0];//这里出现<em>未处理</em>NullReferenceException :未将对象引用设置到对象的实例 ...rn this.Luname.Text = dr["usname"].ToString();rn this.lemail.Text = dr["email"].ToString();rn this.Textname.Text = dr["name"].ToString();rnrnrnrn[/code]rnrn我是一个初学者,这原来这个写法是用在access上的,现在我用在mysql上了!
未处理nullreferenceException的错误!
for (int i = 0; i < nodes3.Count; i++)rn rn if (nodes3[i].HasChildNodes)rn rn for (int j = 0; j < nodes3[i].ChildNodes.Count; j++)rn rn if ((nodes3[i].ChildNodes[j].Name) == "Rooms")rn rn XmlNodeList nodes5 = doc.SelectNodes(@"Advertisement/Semantic_Description/Content/Real-Estate/R-E_Object/Rooms");rn for (int l = 0; l < nodes5[i].ChildNodes.Count; l++)rn rn if (nodes5[l].HasChildNodes)rn rn //MessageBox.Show(nodes5[i].InnerText);rn strRooms = nodes5[i].InnerText.ToString();rn //MessageBox.Show(strRooms);rnrn rnrn rn if (nodes3[i].ChildNodes[j].Name == "Address")rn rnXmlNodeList nodes6 = doc.SelectNodes(@"Advertisement/Semantic_Description/Content/Real-Estate/R-E_Object/Address");rn for (int l = 0; l < nodes6[i].ChildNodes.Count; l++)rn rn if (nodes6[l].HasChildNodes)rn rn strRooms = nodes6[i].InnerText.ToString();rn MessageBox.Show(strRooms);rnrn rnrn rnrnrn rnrnrn提示这句错了 for (int l = 0; l < nodes5[i].ChildNodes.Count; l++)rnrn<em>未处理</em>nullreferenceException的错误!未将对象引用设置到对象的实例。rnrn但我的xml是这样的rnrnrnrn 1 roomrnrnrn rnrn XXX Streetrnrnrn BeijingrnrnrnRooms的节点就能读,读到address下面的结点就报错,为什么??
用户代码未处理nullreferenceexception
编译程序出现大量用户代码<em>未处理</em><em>nullreferenceexception</em> 菜鸟 求助rn[img=https://img-bbs.csdn.net/upload/201405/03/1399099406_51849.png][/img]
用户代码未处理 NullReferenceException
我做的一个注册用户的页面,调试时注册函数里提示"未将对象引用设置到对象的实例。",搜了一下都没解决问题,所以来此求助,谢谢先^^rn下面是出错的那一句rn[code=C#]int flag = (int)command.ExecuteScalar();rn[/code]rn下面是完整的函数rn[code=C#] protected void Button1_Click(object sender, EventArgs e)rn rn string user = "";rn string pwd = "";rn user = txtUserName.Text.Trim();rn pwd = txtPassword.Text.Trim();rn string SqlString = "select username from [user] where username='" + user.Replace("'", "") + "'";rn using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["database"].ConnectionString))rn rn conn.Open();rn SqlCommand command = new SqlCommand(SqlString, conn);rn int flag = (int)command.ExecuteScalar();rn if (flag == 0) //用户名未注册rn rn string SqlString2 = "insert into user values ('" + user + "','" + pwd + "'";rn SqlCommand command2 = new SqlCommand(SqlString2, conn);rn command2.ExecuteNonQuery();rn Session["UserSession"] = user;rn rn else //用户名已被注册rn rn lblMsg.Text = "用户名已存在,请重新注册";rn txtUserName.Text = "";rn txtPassword.Text = "";rn txtConfirm.Text = "";rn rn rnrn rn[/code]
未处理 NullReferenceException错误
读取数据部分被写到了类库m_class,在DataGridView窗体m_usermange.cs 中实例化了这个类,然后在m_useredit.cs修改,刷新m_usermange.cs 中的数据库的DGV控件内容。目前,修改读取都没问题,但是最后调用m_usermange.cs的刷新方法时,提示refresh.form_load()这句:"<em>未处理</em> NullReferenceException错误" ,哪位高人能告诉我为什么。如果不用类库直接代码都写进窗体中就没问题。rnrn[code=C#]rnrnm_class.dllrnrnpublic class m_userlistrnrnpublic DataGridView userlist_load(DataGridView u_data)rn rnrn //读取用户列表rn rn m_sql_conn fee_conn = new m_sql_conn();rn SqlConnection conn = new SqlConnection(fee_conn.sql_conn());rn SqlCommand cmd = new SqlCommand(userload,conn);rn find_do = new SqlDataAdapter();rn find_do.SelectCommand = cmd;rn ds = new DataSet();rn tryrn rn u_data.RowHeadersVisible = false;rn find_do.Fill(ds, "rs");rn rn catch(System.Exception)rn rn MessageBox.Show("数据库连接失败", "数据读未读取", MessageBoxButtons.OK);rn return null;rn rn u_data.DataSource = ds.Tables["rs"]; rn rn for (int k = 0; k < u_data.Columns.Count; k++)rn rn u_data.Columns[k].SortMode = DataGridViewColumnSortMode.NotSortable;rn rn return u_data;rn rnrn[/code]rnrnrn[code=C#]rnrnDataGridView控件所在窗体 m_usermange.cs DGV控件名:d_userlistrnrnprivate void formload()rn rn m_userlist users = new m_userlist();rn users.userlist_load(d_userlist);rn rnrn public void form_load()rn rn formload();rn rnrn[/code]rnrn[code=C#]rnrn修改数据库窗体 m_useredit.cs 代码:rnrn[code=C#]rnm_userlist card_up = new m_userlist();rncard_up.user_save(int.Parse(m_usermange.user_id), t_pwd.Text, t_rname.Text, flag, sale, usermanage,rnsalemanage, allreport,classreport,dbset,dbmanage, deadcard, cardnumset, cardmanage);rn m_usermange refresh = new m_usermange();rn refresh = (m_usermange)this.Owner;rn refresh.form_load();[/code]rn
this.invoke 未处理, nullReferenceException
rn delegate void DlgErosionStatus(bool Status);rnrn..........rnrnrn if (this.InvokeRequired)rn rn DlgErosionStatus myDlgErosionStatus = new DlgErosionStatus(ErosionStatusEvent);rn Object[] myObject = new Object[] Status ;rn this.Invoke(myDlgErosionStatus, myObject);;<-------------------(<em>未处理</em>, nullReferenceException)rn rn rnrnrn请各位朋友,帮忙分析一下
VB.NET 未处理 NullReferenceException 问题
Private Sub NumericUpDown1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles NumericUpDown1.ValueChangedrn For i As Integer = 0 To Me.ListView1.Items.Count - 1rn If Me.ListView1.Items(i).Selected Thenrn If Me.NumericUpDown1.Value > Me.ListView1.Items(i).SubItems(1).Text Thenrn Me.NumericUpDown1.Value = 1rn MsgBox("Error")rn Returnrn End Ifrn End Ifrn Nextrn End Subrn rn[img=http://b.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=6bcc29c1b812c8fcb4a6fecbcc33be7d/4ec2d5628535e5ddfe56fe3e77c6a7efcf1b62dc.jpg][/img]rnrn[img=http://e.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=35556484b219ebc4c02d7e9fb216e3c4/94cad1c8a786c917335a09d8c83d70cf3ac757f1.jpg][/img]rnrnrnrn以上为一段测试代码。rnrn在一个WINFORM上有一个NumericUpdown和一个LISTVIEW。在NumericUpdown1控件的ValueChanged事件中编写了当NumericUpdown的值在改变时,检查Numericupdown的值是否大于LISTVIEW选中记录的第2列的值.如果大于则提示报错,并将Numericupdown的值复位为1.rnrn现在的问题是,只要检查到Numericupdown的值大于LISTVIEW选中记录第2列时,弹出无可用源报错对话框,点击确定按钮后就会出现“<em>未处理</em> NullReferenceException”错误。无法继续运行下去。有时偶尔不会,多试二次又会。调试发现,只要不加入MSGBOX("ERROR"),就没问题,加上MSGBOX("ERROR")就会异常。请高手讲讲这是为什么。怎么去调试和处理这种异常情况?出错的原因在哪?rnrn测试环境W7 X64 With SP1+VB.NET 2010 With SP1
C#,用户代码未处理NullReferenceException?高手帮忙!
using System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.Data.OleDb;rnusing System.IO;rnrnnamespace 车库管理系统rnrn public partial class Form1 : Formrn rn private DataSet dsnew;rn private OleDbCommand command = new OleDbCommand();rn private OleDbConnection connection;rn private OleDbDataAdapter adapter;rn private DataTable thetable = new DataTable();rn public Form1()rn rn InitializeComponent();rn rn public int a = 0;rnrn private void 信息BindingNavigatorSaveItem_Click(object sender, EventArgs e)rn rn this.Validate();rn this.信息BindingSource.EndEdit();rn this.信息TableAdapter.Update(this.userDataSet.信息);rnrn rn private void Form1_Load(object sender, EventArgs e)rn rn // TODO: 这行代码将数据加载到表“userDataSet.信息”中。您可以根据需要移动或移除它。rn this.信息TableAdapter.Fill(this.userDataSet.信息);rn rnrn private void pictureBox1_Click(object sender, EventArgs e)rn rn this.textBox8.Text = "请输入停车卡号关键字";rn this.textBox8.Focus();rn textBox8.SelectAll();rn a = 1;rnrn rn private void pictureBox2_Click(object sender, EventArgs e)rn rn this.textBox8.Text = "请输入车主姓名关键字";rn a = 2;rn this.textBox8.Focus();rn textBox8.SelectAll();rnrn rnrnrn private void pictureBox5_Click(object sender, EventArgs e)rn rn Form2 f2 = new Form2(); //返回rn f2.Show();rn this.Hide();rn rnrn private void button2_Click(object sender, EventArgs e)rn rn if (a == 0)rn rn MessageBox.Show("请选择查询条件!");rn textBox8.Focus();rn textBox8.SelectAll();rn rnrnrn if (a == 1)rn rn string con = "Select * from 信息 where 停车卡号 like '%" + textBox8.Text + "%'";rn connection = new OleDbConnection();rn connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\车库管理系统\\user.mdb";rn connection.Open();rn command.Connection = connection;rn command.CommandType = CommandType.Text;rn command.CommandText = con;rn adapter = new OleDbDataAdapter("Select * From 信息", connection);rn adapter.SelectCommand = command;rn dsnew = new DataSet();rn adapter.Fill(dsnew, "user");rn thetable = dsnew.Tables["user"];rn 信息DataGridView.DataSource = thetable;rn rn if (a == 2)rn rn string con = "Select * from 信息 where 车主姓名 like '%" + textBox8.Text + "%'";rn connection = new OleDbConnection();rn connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\车库管理系统\\user.mdb";rn connection.Open();rn command.Connection = connection;rn command.CommandType = CommandType.Text;rn command.CommandText = con;rn adapter = new OleDbDataAdapter("Select * From 信息", connection);rn adapter.SelectCommand = command;rn dsnew = new DataSet();rn adapter.Fill(dsnew, "user");rn thetable = dsnew.Tables["user"];rn 信息DataGridView.DataSource = thetable;rn rn rn rnrn private void button3_Click(object sender, EventArgs e)rn rn Form1 f1 = new Form1();rn f1.Show();rn this.Hide();rn rnrn private void button4_Click(object sender, EventArgs e)rn rn if (MessageBox.Show("你确定删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)rn 信息DataGridView.Rows.RemoveAt(信息DataGridView.SelectedRows[0].Index);rn elsern rn Form1 f1 = new Form1();rn f1.Show();rn this.Hide();rn rn rnrn private void 信息DataGridView_CurrentCellChanged(object sender, EventArgs e)rn rn[color=#FF0000] //信息DataGridView内容显示到textbox里,可是加入这个事件之后,进行查询、删除的操作就无法调试通过了,提示(this.textBox2.Text = this.信息DataGridView.CurrentRow.Cells[0].Value.ToString(); “未将对 象引用设置到对象的实例”。)[/color]rnrn this.textBox2.Text = this.信息DataGridView.CurrentRow.Cells[0].Value.ToString(); rn this.textBox3.Text = this.信息DataGridView.CurrentRow.Cells[1].Value.ToString();rn this.textBox4.Text = this.信息DataGridView.CurrentRow.Cells[2].Value.ToString();rn this.textBox5.Text = this.信息DataGridView.CurrentRow.Cells[3].Value.ToString();rn this.textBox6.Text = this.信息DataGridView.CurrentRow.Cells[4].Value.ToString();rn this.textBox7.Text = this.信息DataGridView.CurrentRow.Cells[5].Value.ToString();rn rnrnrnrnrnrn rnrn
Application.Run(new Form_main()); 未处理NullReferenceException
请问各位:rnrn WINFORM程序下,运行程序,我点击按钮后,老出现rnApplication.Run(new Form_main()); <em>未处理</em>NullReferenceException 未将对象引用设置到对象的实例中。rnrnrn这是什么原因呀?百思不得其解,大家有遇到这样的情况吗?rnrnrn以下是BUTTON的事件。rn private void button32_Click(object sender, EventArgs e)rn rn if (CANLINK.TesterPresent((byte)0).ToString() == "-1")rn rn CANLINK.OpenCan();rn Thread.Sleep(5);rn CANLINK.InitCan();rn label61.Text = "正在联机...";rn Thread.Sleep(5);rn CANLINK.StartCan();//打开CANrn rn CANLINK.START_STOP((byte)0, (byte)0, (byte)5, (byte)1);rn StringBuilder Responsechar = new StringBuilder();rn string Responstr;rn char[] charesult = new char[255];rn Responsechar = CANLINK.TesterPresent(0);rn Responstr = Responsechar.ToString();rn if (Responstr.Substring(0, 2) == "01")rn rn label61.Text = "联机成功,与管理程序联机!";rn rn if (Responstr.Substring(0, 2) == "00")rn rn label61.Text = "联机成功,与驻留程序联机!";rn rn if (Responstr.Substring(0, 2) != "00" && Responstr.Substring(0, 2) != "01")rn rn MessageBox.Show("联机失败!");rn return;rn rn //发送种子与获取权限rn char[] Receivedat = new char[10];rn Responsechar = CANLINK.GSecurityAccess();rn string mykey = Responsechar.ToString();//种子rn //换算种子rn int mynewkey = Convert.ToInt32(mykey, 16);rn int myfactory = Convert.ToInt32(Responstr.Substring(2, 2), 16);rn string unlock = CAN_SeedToKey(mynewkey, (byte)myfactory);rn //发送UNLOCKrn StringBuilder Unlockk = new StringBuilder(unlock);rn if (CANLINK.SSecurityAccess(Unlockk))rn rn label61.Text = "联机成功,获得标定权限!";rn rn elsern label61.Text = "联机成功,获取权限失败!";rnrn if (0x62 != CANLINK.DiagnosticSessionControl(0x62))rn rn label61.Text = "进入管理程序失败!不能正确设置DAQ!";rn return;rn rn Thread.Sleep(100);rn int LastODT = InitODT();rn //开始DAQrn CANLINK.START_STOP((byte)1, (byte)0, (byte)5, (byte)1);rn timer_ecu25.Start();rn rnrnrnCANLINK 是我自己写的一个类:rnrnusing System;rnusing System.Collections.Generic;rnusing System.Text;rnusing System.Runtime.InteropServices;rnusing Microsoft.Win32;rnrnnamespace Electric_testrnrn class CANLINKrn rn unsafe public struct CAN_OBJrn rn public UInt32 ID;rn public UInt32 TimeStamp;rn public byte TimeFlag;rn public byte SendType;rn public byte RemoteFlag;//是否是远程帧rn public byte ExternFlag;//是否是扩展帧rn public byte DataLen;rn [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]rn public byte[] Data;rn [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]rn public byte[] Reserved;rn rnrn //OpenCANrn [DllImport("CANLINK.dll",rn EntryPoint = "OpenCan",rn CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]rn public static extern uint OpenCan();rnrn //InitCANrn [DllImport("CANLINK.dll",rn EntryPoint = "InitCan",rn CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]rn public static extern uint InitCan();rnrn //STARTCANrn [DllImport("CANLINK.dll",rn EntryPoint = "StartCan",rn CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]rn public static extern uint StartCan();rnrn //CLOSECANrn [DllImport("CANLINK.dll",rn EntryPoint = "CloseCan",rn CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]rn public static extern uint CloseCan();rnrn //RESTCANrn [DllImport("CANLINK.dll",rn EntryPoint = "ResetCan",rn CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]rn public static extern uint ResetCan();rnrnrn //SendDatarn [DllImport("CANLINK.dll",rn EntryPoint = "SenddataCan",rn CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]rn //unsafe public static extern ulong SenddataCan([MarshalAs(UnmanagedType.LPStruct)]CAN_OBJ MySendOBJ, ulong Len);rn unsafe public static extern ulong SenddataCan(ref CAN_OBJ MySendOBJ, ulong Len);rnrn //ClearBufferCanrn [DllImport("CANLINK.dll",rn EntryPoint = "ClearBufferCan",rn CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]rn public static extern uint ClearBufferCan();rnrnrn //GetReceiveNumCanrn [DllImport("CANLINK.dll",rn EntryPoint = "GetReceiveNumCan",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn public static extern ulong GetReceiveNumCan();rnrn //ReadErrInfoCan()rn [DllImport("CANLINK.dll",rn EntryPoint = "ReadErrInfoCan",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn public static extern uint ReadErrInfoCan();rnrn //ReceiveDatarn [DllImport("CANLINK.dll",rn EntryPoint = "ReceivedataCan",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn //unsafe public static extern ulong SenddataCan([MarshalAs(UnmanagedType.LPStruct)]CAN_OBJ MySendOBJ, ulong Len);rn unsafe public static extern ulong ReceivedataCan(ref CAN_OBJ MyRecOBJ, ulong Len);rnrnrn [DllImport("CANLINK.dll",rnEntryPoint = "TesterPresent", //联机rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn //unsafe public static extern ulong SenddataCan([MarshalAs(UnmanagedType.LPStruct)]CAN_OBJ MySendOBJ, ulong Len);rn unsafe public static extern StringBuilder TesterPresent(byte status);rnrnrn [DllImport("CANLINK.dll",rnEntryPoint = "GSecurityAccess", //获取种子rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn //unsafe public static extern ulong SenddataCan([MarshalAs(UnmanagedType.LPStruct)]CAN_OBJ MySendOBJ, ulong Len);rn unsafe public static extern StringBuilder GSecurityAccess();rnrn [DllImport("CANLINK.dll",rnEntryPoint = "SSecurityAccess", //发种子rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn //unsafe public static extern ulong SenddataCan([MarshalAs(UnmanagedType.LPStruct)]CAN_OBJ MySendOBJ, ulong Len);rn unsafe public static extern bool SSecurityAccess(StringBuilder unlock);rnrn [DllImport("CANLINK.dll",rnEntryPoint = "DiagnosticSessionControl", //状态切换rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn //unsafe public static extern ulong SenddataCan([MarshalAs(UnmanagedType.LPStruct)]CAN_OBJ MySendOBJ, ulong Len);rn unsafe public static extern byte DiagnosticSessionControl(byte status);rnrnrn [DllImport("CANLINK.dll",rn EntryPoint = "ReadDataByID",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern StringBuilder ReadDataByID(int data_id);rnrnrn [DllImport("CANLINK.dll",rn EntryPoint = "WritDataByID",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern byte WritDataByID(int data_id, StringBuilder data);rnrn [DllImport("CANLINK.dll",rn EntryPoint = "Reset",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern byte Reset(byte id);rnrn [DllImport("CANLINK.dll",rn EntryPoint = "AUTO_DAQ",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern byte AUTO_DAQ(byte DAQ_NO, byte ODT_NO, byte ELE, int ELE_Length, StringBuilder Address);rnrn [DllImport("CANLINK.dll",rn EntryPoint = "START_STOP",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern byte START_STOP(byte Stauts, byte DAQ_NO, byte Last_ODT, byte Event_NO);rnrn [DllImport("CANLINK.dll",rn EntryPoint = "Receive_DAQ",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern StringBuilder Receive_DAQ(byte ODT);rnrnrn [DllImport("CANLINK.dll",rn EntryPoint = "InitReceive",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern void InitReceive(ref CAN_OBJ pDAQ, ref CAN_OBJ pCCP, ref CAN_OBJ[] p15765);rnrnrn //void ManageThread(BOOL Thread_flag)rn [DllImport("CANLINK.dll",rn EntryPoint = "ManageThread",rn CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]rn unsafe public static extern void ManageThread(bool Thread_flag);rnrnrn rnrn
sql+gridview运行时出现未处理nullreferenceexception
建立一个数据库再显示于gridview上,如下图所示:rn[img=https://img-bbs.csdn.net/upload/201708/23/1503497733_964330.png][/img]rn要实现的功能暂时是数据库的显示、修改、删除、增加,显示要求工艺号文本框内只有数字,就像图中那样,但是在该条件下再进行修改功能(增加、删除功能正常)就会出现“<em>未处理</em><em>nullreferenceexception</em>,未将对象引用设置到对象的实例”的提示,求教一下该情况是什么原因,有什么解决办法?rn显示和修改代码如下:rn private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)rn rn //将各列的值对应显示于各文本框//rn string str = dataGridView1.SelectedCells[0].Value.ToString();rn str = str.Replace("工艺", "");//显示项去除“工艺”二字rn txtNo.Text=str;rn txtZJ.Text = dataGridView1.SelectedCells[2].Value.ToString();rn txtHD.Text = dataGridView1.SelectedCells[3].Value.ToString();rn txtRA.Text = dataGridView1.SelectedCells[7].Value.ToString();rn txtBC.Text = dataGridView1.SelectedCells[4].Value.ToString();rn cobDS.Text = dataGridView1.SelectedCells[5].Value.ToString();rn txtXL.Text = dataGridView1.SelectedCells[6].Value.ToString();rn txtCL.Text = dataGridView1.SelectedCells[1].Value.ToString();rn string str2 = dataGridView1.SelectedCells[8].Value.ToString();rn switch (str2)rn rn case "外形": radioButton1.Checked = true; break;rn case "内孔": radioButton2.Checked = true; break;rn rn rn private void button1_Click(object sender, EventArgs e)rn rn DataTable dt = ds.Tables["tb"];rn sda.FillSchema(dt, SchemaType.Mapped);rn DataRow dr = dt.Rows.Find(txtNo.Text);//编号rn //以下句子将各文本框中的内容放于对应列下rn dr["工艺号"] = "工艺" + this.txtNo.Text.Trim();rn dr["钼丝直径(mm)"] = this.txtZJ.Text.Trim();rn dr["工件厚度(mm)"] = this.txtHD.Text.Trim();rn dr["表面光洁度"] = this.txtRA.Text.Trim();rn dr["钼丝补偿(mm)"] = this.txtBC.Text.Trim();rn dr["切割次数"] = this.cobDS.Text.Trim();rn dr["切割效率(mm2/分钟)"] = this.txtXL.Text.Trim();rn dr["材料说明"] = this.txtCL.Text.Trim();rn if (radioButton1.Checked)rn rn dr["形状"] = "外形";rn rn else if (radioButton2.Checked)rn rn dr["形状"] = "内孔";rn rn SqlCommandBuilder cmdbuider = new SqlCommandBuilder(sda);rn sda.Update(dt);rn conn.Close();rn
未处理NullReferenceException ,桌面系统不停的报这个错误 ,在线等!!!
private void FillGridQueryPrice()rn rn this.curSelectedItem = ApplicationConfiguration.EVSItem.QueryPrice;rn this.splItem.PanelVisibility = this.IsReadNodes ? DevExpress.XtraEditors.SplitPanelVisibility.Both : DevExpress.XtraEditors.SplitPanelVisibility.Panel2;rn this.gvMain.FocusedRowChanged -= new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gvMain_FocusedRowChanged);rn this.gvMain.RowCellStyle -= new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(this.gvMain_RowCellStyle);rn initerOfGrid.CurEVSItem = Configuration.ApplicationConfiguration.EVSItem.QueryPrice;rn initerOfGrid.Init(this.gvMain); rn this.dtReportCheck = BLLFactory.DataAccess.CreateReportCheck().GetData().Tables[0];rn this.gvMain.Columns["IsFromWeb"].ColumnEdit = this.cmbImage2;rn if(this.dtQueryPrice == null || this.IsReLoadQP == true)rn rn DevExpress.Utils.WaitDialogForm frmWait = new DevExpress.Utils.WaitDialogForm("正在搜索询价信息,请稍候...", " ", new Size(300,50), this);rn tryrn rn frmWait.Show();rn base.Cursor = Cursors.WaitCursor;rn dtQueryPrice=new DataTable();rn if(this.txtBName.Text.Trim()==string.Empty)rn rn if(txtStartDate.Text!=string.Empty&&txtEndDate.Text!=string.Empty)rn rn dtQueryPrice=myQueryPrice.GetQueryPriceByCondition(this.txtBName.Text.Trim(),txtStartDate.Text,txtEndDate.Text,cmbHType.Text,Configuration.EVSConfiguration.CityId).Tables[0];rn rn elsern rn dtQueryPrice = myQueryPrice.GetQueryPrices(Configuration.EVSConfiguration.UserId).Tables[0];rn txtStartDate.Text=DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd");rn txtEndDate.Text=DateTime.Today.ToString("yyyy-MM-dd");rn rn rn elsern rn if(txtStartDate.Text!=string.Empty&&txtEndDate.Text!=string.Empty)rn rn dtQueryPrice=myQueryPrice.GetQueryPriceByCondition(this.txtBName.Text.Trim(),txtStartDate.Text,txtEndDate.Text,cmbHType.Text,Configuration.EVSConfiguration.CityId).Tables[0];rn rn elsern rn dtQueryPrice=myQueryPrice.GetQueryPriceByCondition(this.txtBName.Text.Trim(),"1900-01-01",DateTime.Today.ToShortDateString(),cmbHType.Text,Configuration.EVSConfiguration.CityId).Tables[0];rn rn rn rn rn catch (System.Data.SqlClient.SqlException ex)rn rn throw new Exception(ex.Message);rn rn finallyrn rn base.Cursor = Cursors.Default;rn rn this.gridMain.DataSource = dtQueryPrice;rn elsern rn this.gridMain.DataSource = null;rn
未处理 NullReferenceException 未将对象引用设置到对象的实例
原因: 调用了a.shuxing1 = bianliang1; 但是呢,这个a其实是一个null 所以就出错了 解决办法(确保a不为null): 先ClassA a = new ClassA(); 再a.shuxing1 = bianliang1;  ...
使用FileStream的时候出现未处理 NullReferenceException
[code=C#] string KeyWordTxt = "Keyword.txt";rn rn if (!File.Exists(KeyWordTxt))rn rn FileStream FSO = new FileStream(KeyWordTxt, FileMode.CreateNew, FileAccess.Write);rn StreamWriter FSO_write = new StreamWriter(FSO);rn FSO_write.Flush();rn FSO_write.BaseStream.Seek(0, SeekOrigin.Begin);rn FSO_write.Write("TESTTESTTESTTESTTEST");rn FSO_write.Flush();rn FSO_write.Close();rn MessageBox.Show("关键字文件不存在建立关键字文件!");rnrn rn elsern rn FileStream FSO = new FileStream(KeyWordTxt, FileMode.Open, FileAccess.Read);rn StreamReader FSO_Read = new StreamReader(FSO);rn FSO_Read.BaseStream.Seek(0, SeekOrigin.Begin);rn KeyWord.Text = FSO_Read.ReadLine();rn FSO_Read.Close();rn //文件存在读取数据rn [/code]rnrn建立文件正常rn但是读取文件的时候就出现rn<em>未处理</em> NullReferenceExceptionrn直接指向KeyWord.Text = FSO_Read.ReadLine();rn
未将对象引用设置到对象的实例未处理NullreferenceException
光标在if(comboclass.selectedvalue.tostring() != "0")rn这里停住了,需要引用什么?
求助: 程序老是提示 未处理的NullReferenceException,头疼!
dim s as stringrndim an_single() as string rnDim o As Integer, st As StringrnDim An_s As Integer = 0, An_d As Integer = 0rnrn[button click ]rn.....rnIf s <> "" Thenrn If Mid(s, 1, 1) <> "@" Then ' 为单选题rn sig_foranswer(s) ' 对应答rn Else '为多选题rn An_single(i) = Mid(s, 2, s.Length - 1)rn i = i + 1rn An_d = An_d + 1rn End IfrnEnd Ifrn.....rn[end button ]rnrnrnPrivate Sub sig_foranswer(ByVal str As String)rn If str <> "" Then '字符组和题号都不为空的情况下rn r = str.Lengthrn For o = 1 To r ' o 为计数器 一般都为5rn st = Mid(str, o, 1) '第 o 位开始的第一个字符rn An_single(o) = strn i = i + 1rn An_s = An_s + rrn Nextrn Elsern End IfrnEnd Subrnrn程序在 An_single(i) = Mid(s, 2, s.Length - 1) 或 An_single(o) = st 处都出错,错误提示为:rn<em>未处理</em>的 NullReferenceExceptionrn使用“NEW"关键字创建对象实例。rn在调用方法前通过检查确定对象是否为空。rnrn此处我没有创建对象的实例啊,只是给一个字符数组赋值而已,请大家帮忙看看,谢谢。rn
用户代码未处理 NullReferenceException 错误的解决办法
俺刚学报表,什么都不懂。rn在aspx页面放了一个ReportViewer控件,后绑定Access数据库,然后新建了一个rdlc报表,很简单做了一个列出库里的表中某列数据的表,一运行,出现以下错误。rnget rn if ((this._connection == null)) rn this.InitConnection(); ---这里提示:用户代码<em>未处理</em> NullReferenceExceptionrn rn return this._connection;rn rnrn以上代码都是2010自动生成的,请教应该怎样解决。
未将对象引用设置到对象的实例。未处理NullReferenceException
在敲机房重构的过程中,遇到了各种各样的问题,其中有这样一个问题:“未将对象设置到对象的实例”,如下图:         这个问题真的很常见,也很令人纠结;尤其是这段时间我旁边的好多人都遇到了这个问题,调试了好多天都找不到解决办法,真是折磨人啊。       那么这个错误到底是哪里的问题呢?其实,这个有很多方面的原因,我就我所遇到的情况说一下。       1、  未使用new初始化对象。
未处理 NullReferenceException Object reference not set to an instance of an object.
response = (HttpWebResponse)request.GetResponse();//这里抛的异常
NullReferenceException???
用VB在Partial Public Class Page1下定义变量出现<em>未处理</em>NullReferenceException提示框。。求解决办法。。。!rnrn代码如下rnPartial Public Class Page1rnrn Inherits PhoneApplicationPagernrn Dim a1 = Convert.ToInt32(Button1.Content)
动态添加Button 不知道为什么报异常“NullReferenceException”
[code=csharp]rnstring[] src = new string[dt.Rows.Count];rn string src1;rn for (int i = 0; i < dt.Rows.Count; i++)rn rn Button btn = new Button();rn rn src1 = dt.Rows[i].ItemArray[0].ToString();rn src[i] = src1;rn rn btn.BackColor = Color.Fuchsia;rn btn.Font = new Font("黑体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));rn btn.ForeColor = Color.White;rn btn.Location = new Point(0, 42 * i);rn btn.Name = src1;rn btn.Size = new Size(773, 42);rn //btn.TabIndex = 0;rn btn.Text = src1;rn btn.UseVisualStyleBackColor = false;rn btn.Click += new EventHandler(btn_Click);rn panel1.Controls.Add(btn);//这里报异常:NullReferenceException: 未将对象引用设置到对象的实例rn rn[/code]rn[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/8.gif][/img]为什么呢? 找不到哪里出问题了啊
求助 C#程序异常 "处理NullReferenceException"
显示:"处理NullReferenceExceptionrn未将对象引用设置到对象的实例"rnrn以下这段程序变为黄色: "string[] strContent = FileContent.Split();"rnrn以下为程序中的一段,请各住指教下:rn//鼠标响应方法rn private void HelloWorld_MouseDown(object sender, MouseEventArgs e)rn rn if (e.Button == MouseButtons.Left)rn rn ArrayList listContent = new ArrayList();rn //将FileContent按照空格或者制表符分割成字符串数组 rn string[] strContent = FileContent.Split();rn foreach (string str in strContent)rn rn if (str != "")rn rn listContent.Add(str);rn rn rn string strDislpay = "";rn foreach (object obj in listContent)rn rn string str = obj as string;//obj转换为string类型rn if (str != null)rn rn strDislpay += str + System.Environment.NewLine;//????????????????????rn rn MessageBox.Show(strDislpay);rn rn
用户代码未处理NullReferenceException 未将对象引用设置到对象的实例
string mystr = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; rn用户代码<em>未处理</em>NullReferenceExceptionrn未将对象引用设置到对象的实例rnrn求大神解决rnrn下面是全部代码rnrnusing System;rnusing System.Collections.Generic;rnusing System.Linq;rnusing System.Web;rnusing System.Data.SqlClient;rnusing System.Data;rnusing System.Web.Configuration;rnrn/// rn///commonclass 的摘要说明rn/// rnpublic class CommonClassrnrn public CommonClass()rn rn //rn //TODO: 在此处添加构造函数逻辑rn //rn rn public SqlConnection GetConnection()rn rn string mystr = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;rn SqlConnection myconn = new SqlConnection(mystr);rn return myconn;rn rn public string MessageBox(string TxtMessage, string Url)rn rn string str;rn str = " ";rn return str;rn rn public Boolean ExecSQL(string sqlStr)rn rn SqlConnection myconn = GetConnection();rn myconn.Open();rn SqlCommand mycmd = new SqlCommand(sqlStr, myconn);rn tryrn rn mycmd.ExecuteNonQuery();rn myconn.Close();rn rn catchrn rn myconn.Close();rn return false;rn rn return true;rn rn public DataSet GetDataSet(string sqlstr, string TableName)rn rn SqlConnection myconn = GetConnection();rn myconn.Open();rn SqlDataAdapter adapt = new SqlDataAdapter(sqlstr, myconn);rn DataSet ds = new DataSet();rn adapt.Fill(ds, TableName);rn myconn.Close();rn return ds;rn rn public int checkLogin(string loginName, string loginPwd)rn rn SqlConnection myconn = GetConnection();rn SqlCommand mycmd = new SqlCommand("select count(*) from tb_user where Name = @loginName and PassWord = @loginPwd",myconn);rnrn mycmd.Parameters.Add(new SqlParameter("@loginName",SqlDbType.VarChar,20));rn mycmd.Parameters["@loginName"].Value = loginName;rn mycmd.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.VarChar, 20));rn mycmd.Parameters["@loginPwd"].Value = loginPwd;rn myconn.Close();rnrn int i = Convert.ToInt32(mycmd.ExecuteScalar());rn mycmd.Dispose();rn mycmd.Clone();rn return i;rn rn public string RandomNum(int n)rn rn string strchar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";rnrn string[] VcArray = strchar.Split(',');rn string VNum = "";rnrn int temp = -1;rn Random rand = new Random();rn for (int i = 1; i < n + 1; i++)rn rn if (temp != -1)rn rn rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));rn rn int t = rand.Next(61);rn if (temp != -1 && temp == t)rn rn return RandomNum(n);rn rn temp = t;rn VNum += VcArray[t];rn rn return VNum;rn rn public SqlDataReader ExecReader(string sqlstr)rn rn SqlConnection myconn = GetConnection();rn myconn.Open();rn SqlCommand cmd = new SqlCommand(sqlstr, myconn);rn SqlDataReader sdr = cmd.ExecuteReader();rn myconn.Close();rn return sdr;rn rn
用户代码未处理 NullReferenceException未将对象引用设置到对象的实例。
Web.config配置文件rn[code=C#]rn rn [/code]rn数据库连接类rn[code=C#]public class SqlHelprnrn string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;rn SqlConnection sqlConnection = null;rn SqlCommand sqlCommand = null;rn SqlDataAdapter sqlDataAdapter = null;rnrn public DataSet ExecuteDataSet(string sql)rn rn sqlConnection = new SqlConnection(connectionString);rn sqlCommand = new SqlCommand(sql, sqlConnection);rn DataSet ds = new DataSet();rn sqlConnection.Open();rn sqlDataAdapter.Fill(ds);rn sqlConnection.Close();rn return ds;rn [/code]rn[code=C#]protected void Page_Load(object sender, EventArgs e)rn rn string sql = "select * from userinfo";rn DataSet ds = new DataSet();rn ds = sqHelp.ExecuteDataSet(sql);rn this.GridView1.DataSource = ds.Tables["userinfo"].DefaultView;rn this.GridView1.DataBind();rn [/code]rnsqlDataAdapter.Fill(ds);这一行报错如下:用户代码<em>未处理</em> NullReferenceException未将对象引用设置到对象的实例。rn这是什么原因?帮帮忙.
用户代码未处理NullReferenceException: 未将对象引用设置到对象的实例
我做一个设备保养管理系统,用按钮事件来查询在两个事件段需要保养的设备,我数据库中定义的时间为datetime,通过点击button来查询,不过在查询中老是显示“用户代码<em>未处理</em>NullReferenceException: 未将对象引用设置到对象的实例。排除提示:使用new关键字创建对象实例,在调用方法前检查确定对象是否为空” rn cmd.Parameters("@xh").Value = CDate(StartListBox.SelectedItem.Text) 显示这句诗上面的问题,请高手指教,急啊,在线等。 rnrnProtected Sub ShowBYSQButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowBYSQButton.Click rn rn Dim con As New SqlConnection() rn con.ConnectionString = "Data Source=UPC-DING;Initial Catalog=bysj;User ID=sa ;" rn con.Open() rn Dim sql As String rn sql = "SELECT * FROM [保养申请] where 申请日期 between '@xh' and '@xb'" rn Dim ds As New DataSet() rn Dim adp As New SqlDataAdapter() rn Dim cmd As New SqlCommand rn cmd.Connection = con rn cmd.CommandType = CommandType.Text rn cmd.Parameters.Clear() rn cmd.CommandText = sql rn cmd.Parameters.Add("@xh", SqlDbType.DateTime) rn cmd.Parameters.Add("@xb", SqlDbType.DateTime) rn cmd.Parameters("@xh").Value = CDate(StartListBox.SelectedItem.Text) rn cmd.Parameters("@xb").Value = CDate(EndListBox.SelectedItem.Text) rnrn adp.SelectCommand = cmd rn adp.Fill(ds, "by") rn GridView1.DataSource = ds.Tables("by").DefaultView rn GridView1.DataBind() rn con.Close() rnrn End Sub rnrnrnrn错误具体信息: rn未将对象引用设置到对象的实例。 rn说明: 执行当前 Web 请求期间,出现<em>未处理</em>的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。 rnrn源错误: rnrnrn行 33: ' cmd.Parameters("@xh").Value = CDate(StartListBox.SelectedItem.Text) rn行 34: ' cmd.Parameters("@xb").Value = CDate(EndListBox.SelectedItem.Text) rn行 35: cmd.Parameters("@xh").Value = StartListBox.SelectedItem.Text rn行 36: cmd.Parameters("@xb").Value = EndListBox.SelectedItem.Text rn行 37: rn rnrn源文件: E:\毕业设计作业\保养设备管理\保养申请单.aspx.vb 行: 35 rnrn堆栈跟踪: rnrnrn[NullReferenceException: 未将对象引用设置到对象的实例。] rn 保养设备管理_保养申请单.ShowBYSQButton_Click(Object sender, EventArgs e) in E:\毕业设计作业\保养设备管理\保养申请单.aspx.vb:35 rn System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96 rn System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +117 rn System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31 rn System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32 rn System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72 rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838 rnrn rn
用户代码未处理NullReferenceException未将对象引用设置到对象的实例
[img=https://img-bbs.csdn.net/upload/201510/31/1446295247_964577.png][/img][img=https://img-bbs.csdn.net/upload/201510/31/1446295376_846019.png][/img]
窗口启动时,有时会有 “未处理NullReferenceException”错误,随机的。
C# Winform窗口程序,调试的时候,有时会弹出错误提示如下:rn <em>未处理</em>NullReferenceExceptionrn 未将对象引用设置到对象的实例。rnrn错误指向 Main()函数的rn Application.Run(new MainForm());rn 处。rnrn 请问这种情况一般是怎么了。是不是有些对象为空?但这种错误是随机的啊,有时有有时没有,实在头疼。
C# 捕获未处理的异常
C# 捕获<em>未处理</em>的异常  http://vpp516.blog.163.com/blog/static/5718440520110695514144/ 2011-01-06 09:55:14|  分类: 默认分类|字号 订阅 static class Program { /// /// 应用程序的主入口点。 /// [STAThread
c#图像处理 未处理securityexception
做了一个关于图像放缩的程序 rnRectangle rect = new Rectangle(0, 0, curBitmap.Width, curBitmap.Height);rn BitmapData bmpData = curBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,rn curBitmap.PixelFormat);rn IntPtr ptr = bmpData.Scan0;rn int bytes = curBitmap.Width*curBitmap.Height;rn byte[] grayValues = new byte[bytes];rn [color=#FF0000]System.Runtime.InteropServices.Marshal.Copy(ptr,grayValues,0,bytes);[/color]rnrn //得到横向和纵向的缩放量rn double x = 5;rn double y = 5;rnrn //图像的几何中心rn int halfWidth = (int) (curBitmap.Width/2);rn int halfHeight = (int) (curBitmap.Height/2);rnrn int xz = 0;rn int yz = 0;rn int tempWidth = 0;rn int tempHeight = 0;rn byte[] tempArray = new byte[bytes];rnrn //最临近插值法rn for(int i = 0;i < curBitmap.Width;i++)rn rn for(int j = 0;j < curBitmap.Height;j++)rn rn //以图像的几何中心为坐标原点进行坐标转换rn //按逆向映射法得到输入图像的坐标rn tempHeight = i - halfHeight;rn tempWidth = j - halfWidth;rnrn //在不同的象限进行四舍五入处理rn if(tempWidth > 0)rn rn xz = (int) (tempWidth/x + 0.5);rn rn elsern rn xz = (int) (tempWidth/x - 0.5);rn rn if(tempHeight > 0)rn rn yz = (int) (tempHeight/y + 0.5);rn rn elsern rn yz = (int) (tempHeight/y - 0.5);rn rnrn //坐标逆变换rn tempWidth = xz + halfWidth;rn tempHeight = yz + halfHeight;rn //得到输出图像像素值rn if(tempWidth < 0 || tempWidth >= curBitmap.Width || tempHeight < 0 || tempHeight >= curBitmap.Height)rn rn //缩放后留下的空白部分用白色像素代替rn tempArray[i*curBitmap.Width + j] = 255;rn rn elsern rn tempArray[i*curBitmap.Width + j] = grayValues[tempHeight*curBitmap.Width + tempWidth];rn rn rn rnrn调试的时候报出了这个错误:rn请求“System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限已失败。rn应该是红色部分除了问题 rn之前没有做过图像操作部分的代码,请高手相助!
C#捕获未处理异常
C# winform捕获全局异常  http://www.189works.com/article-43312-1.html 异常处理之ThreadException、UnhandledException及多线程异常处理  http://www.soaspx.com/dotnet/csharp/csharp_20110105_7043.html .Net 下未捕获异常的处理  http://w
HELP!!! NullReferenceException!!!
DataRow newone = allTable.NewRow();rnrnnewone[0] = ++id;rnnewone[1] = name;rnnewone[2] = DateTime.Now.AddSeconds(-60);rnnewone[3] = DateTime.Now;rnnewone[4] = "";rnnewone[5] = "";rnnewone[6] = false;rnnewone[7] = false;rnnewone[8] = "";rnrnallTable.Rows.Add(newone);rnrn程序比较大,我通过不断尝试,发现如果程序不加上面的代码运行很久都没有问题,rn但是加了上面的代码就出现NullReferenceException,未将对象引用设置到对象的实例rnrnrn不知道有没有人知道怎么回事,或者分享一些经验,帮我解决这个问题,rn我调试得快要抓狂了
NullReferenceException的问题
小弟今日写了个程序,通过查找HTML源码里的对应字符显示提示窗口的。rn没十秒执行一次,如果有则弹出消息窗。rn不过运行一段时间之后 就会出现一个异常。不管有没有找对应字符。rn请问是什么问题呀。。。愁死了。rnrn异常信息:rn_______________________________rn有关调用实时(JIT)调试而不是此对话框的详细信息,rn请参见此消息的结尾。rnrn************** 异常文本 **************rnSystem.NullReferenceException: 未将对象引用设置到对象的实例。rn 在 WindowsFormsApplication1.Form1.timer1_Tick(Object sender, EventArgs e)rn 在 System.Windows.Forms.Timer.OnTick(EventArgs e)rn 在 System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)rn 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)rnrnrn************** 已加载的程序集 **************rnmscorlibrn 程序集版本: 2.0.0.0rn Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)rn 基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dllrn----------------------------------------rnAnjianrn 程序集版本: 1.0.0.0rn Win32 版本: 1.0.0.0rn 基本代码: file:///C:/Documents%20and%20Settings/95505/桌面/案件提醒/Anjian.exern----------------------------------------rnSystem.Windows.Formsrn 程序集版本: 2.0.0.0rn Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)rn 基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dllrn----------------------------------------rnSystemrn 程序集版本: 2.0.0.0rn Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)rn 基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dllrn----------------------------------------rnSystem.Drawingrn 程序集版本: 2.0.0.0rn Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)rn 基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dllrn----------------------------------------rnmscorlib.resourcesrn 程序集版本: 2.0.0.0rn Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)rn 基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dllrn----------------------------------------rnSystem.Windows.Forms.resourcesrn 程序集版本: 2.0.0.0rn Win32 版本: 2.0.50727.1433 (REDBITS.050727-1400)rn 基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dllrn----------------------------------------rnrn************** JIT 调试 **************rn要启用实时(JIT)调试,rn该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置rnjitDebugging 值。rn编译应用程序时还必须启用rn调试。rnrn例如: rnrnrn rnrnrn启用 JIT 调试后,任何无法处理的异常rn都将被发送到在此计算机上注册的 JIT 调试器,rn而不是由此对话框处理。rnrnrnrnrnrnrn程序源码:rn______________________________________rnrnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.IO;rnusing System.Media;rnusing System.Net;rnusing System.Text;rnusing System.Text.RegularExpressions;rnusing System.Windows.Forms;rnnamespace WindowsFormsApplication1rnrn public partial class Form1 : Formrn rn rn rn public string str, findstr;rn public SoundPlayer plays = new SoundPlayer();rn rnrn public Form1()rn rn InitializeComponent();rn rn rn rnrn private void Form1_Load(object sender, EventArgs e)rn rn webBrowser1.Navigate(@"http://10.100.32.51/crm/login/login.do");rn //webBrowser1.Navigate(@"http://www.baidu.com");rn rn rn timer1.Enabled = false;rn label1.Text = "已停止";rnrn rnrn private void button3_Click(object sender, EventArgs e)rn rn timer1.Enabled = false;rn label1.Text = "已停止";rn rnrn private void button2_Click(object sender, EventArgs e)rn rn webBrowser1.Navigate(@"http://10.100.32.51/crm/frame/mainFrame.jsp?_currentMenuId=13101&_mainUrl=../insure/hscrm/business/icc/claimcase/claimCaseAction.do?act=onQueryWaitDispatchClaimcaseB");rn rnrn private void button1_Click(object sender, EventArgs e)rn rn timer1.Enabled = true;rn label1.Text = "已启动";rn rnrn private void timer1_Tick(object sender, EventArgs e)rn rn str = webBrowser1.Document.Window.Frames["_workspaceMain"].Document.Body.InnerHtml;rn rn findstr = "linkTo01" + "\\u0028" + "'" + "T11";rn rn Regex reg = new Regex(findstr);rn Match mat = reg.Match(str);rn while (mat.Success)rn rn plays.SoundLocation = @"1.wav";rn plays.Play();rn MessageBox.Show("有新案件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);rn mat = reg.Match(str, mat.Index + mat.Length);rn rn rn str = "";rn findstr = "";rn rnrnrn rn rn
c# 未处理 System.IO.IOException
我有两个butten,分别是buttonOK.,buttonOK7rnbuttonOK是用于查找我保存在test.txt 文本中的数据rnbuttonOK7是用于把test.txt 中于textBName相同的数据删除出的!rn我的代码是:rnprivate void buttonOK_Click(object sender, System.EventArgs e)rn rn string str;rn StreamReader stream = new StreamReader(@"f:\Test.txt");rn string str1 = this.textBName.Text;rn while (str1.Length < 8)rn str1 = str1 + " ";rn if (str1.Length > 8)rn str1 = str1.Substring(0, 8);rn for(;;)rn rn str = stream.ReadLine();rn tryrn rn if (str1 == str.Substring(0, 8))rn rn textBoxName.Text = str.Substring(0, 8);rn textBoxAge.Text = str.Substring(8, 3);rn if(str.Substring(8+3,5)=="男")rn this.radioButBoy.Checked =true;rn else rn this.radioButGirl.Checked =true;rn textBoxID.Text = str.Substring(8 + 3 + 5, 20);rn textBoxEmail.Text = str.Substring(36, 25);rn textBoxTelphone.Text = str.Substring(36 + 25, 15);rnrn textBoxPassWord.Text = str.Substring(36 + 25 + 15, 15);rn textBoxAdress.Text = str.Substring(36 + 25 + 30, 30);rn break;rn rn rn catch(NullReferenceException )rn MessageBox.Show ("没你有查找到你的输入的用户!");break;rnrn rn rnrn private void buttonOK7_Click(object sender, EventArgs e)rn rn string str, All=null ; rn StreamReader stream1 = new StreamReader(@"f:\Test.txt");rn while (stream1.ReadLine() != null) rn rn rn str = stream1.ReadLine();rn if (str != textBName.Text)rn All += str;rn else if (str == textBName.Text)rn MessageBox.Show("成功!");rn rn StreamWriter stream2 = new StreamWriter(@"f:\Test.txt");rn stream2.WriteLine(All);rnrn rn执行后遇到问题:<em>未处理</em>的“System.IO.IOException”类型的异常出现rn<em>未处理</em> System.IO.IOExceptionrn Message="文件“f:\\Test.txt”正由另一进程使用,因此该进程无法访问该文件。"rn
c#未处理异常问题
[code=C#][/code] rnrnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.Threading;rnrnnamespace WindowsFormsApplication1rnrn public partial class Form1 : Formrn rn rn int i;rn Thread thread1; //创建线程rn delegate void set_text(string s); //创建委托rn set_text a;rn public Form1()rn rn InitializeComponent();rn rnrn private void Form1_KeyDown(object sender, KeyEventArgs e)rn rnrn rn rn private void _start(object sender, EventArgs e)rn rn thread1 = new Thread(new ThreadStart(run));rn thread1.Start();rn rn rn private void run()rn rn for (i = 0; i ;rn a = new set_text(set_text1);rn rnrn private void exit_Click(object sender, EventArgs e)rn rn // this.Close();rn rnrn private void Form1_FormClosed(object sender, FormClosedEventArgs e)rn rn rn if (thread1.IsAlive)rn thread1.Abort();rn rn rnrnrnrn程序退出时提示<em>未处理</em>异常:rn<em>未处理</em> System.NullReferenceExceptionrn Message=未将对象引用设置到对象的实例。rnrn初学<em>c#</em>,不太理解,求高手!!!!!rnrnrn
c# 未处理 异常
rn我有两个butten,分别是buttonOK.,buttonOK7 rnbuttonOK是用于查找我保存在test.txt 文本中的数据 rnbuttonOK7是用于把test.txt 中于textBName相同的数据删除出的! rn我的代码是: rnprivate void buttonOK_Click(object sender, System.EventArgs e) rn rnstring str; rnStreamReader stream = new StreamReader(@"f:\Test.txt"); rnstring str1 = this.textBName.Text; rnwhile (str1.Length < 8) rn str1 = str1 + " "; rnif (str1.Length > 8) rn str1 = str1.Substring(0, 8); rnfor(;;) rn rnstr = stream.ReadLine(); rntry rn rnif (str1 == str.Substring(0, 8)) rn rntextBoxName.Text = str.Substring(0, 8); rntextBoxAge.Text = str.Substring(8, 3); rnif(str.Substring(8+3,5)=="男") rnthis.radioButBoy.Checked =true; rnelse rnthis.radioButGirl.Checked =true; rntextBoxID.Text = str.Substring(8 + 3 + 5, 20); rntextBoxEmail.Text = str.Substring(36, 25); rntextBoxTelphone.Text = str.Substring(36 + 25, 15); rnrntextBoxPassWord.Text = str.Substring(36 + 25 + 15, 15); rntextBoxAdress.Text = str.Substring(36 + 25 + 30, 30); rnbreak; rn rn rncatch(NullReferenceException ) rnMessageBox.Show ("没你有查找到你的输入的用户!");break; rnrn rn rnrn private void buttonOK7_Click(object sender, EventArgs e) rn rn string str, All=null ; rn StreamReader stream1 = new StreamReader(@"f:\Test.txt"); rn while (stream1.ReadLine() != null) rn rn rn str = stream1.ReadLine(); rn if (str != textBName.Text) rn All += str; rn else if (str == textBName.Text) rn MessageBox.Show("成功!"); rn rn StreamWriter stream2 = new StreamWriter(@"f:\Test.txt"); rn stream2.WriteLine(All); rnrn rn执行后遇到问题:<em>未处理</em>的“System.IO.IOException”类型的异常出现 rn<em>未处理</em> System.IO.IOException rn Message="文件“f:\\Test.txt”正由另一进程使用,因此该进程无法访问该文件。" rn
c# 未处理COMException
类Range的Insert方法无效!rnrnrnrg = wSheet.get_Range(iColumns[6] + Rowindex, iColumns[7] + Rowindex);rn rg.Merge(0);rn rg.Cells[1, 1] = PH[i].M01_AreaCode; rn rg.Interior.ColorIndex = 5;rn Set_style(rg); //这个方法是我自定义样式的rnrnSystem.Runtime.InteropServices.Marshal.ReleaseComObject(rg);rnMicrosoft.Office.Interop.Excel.Range range = wSheet.get_Range(iStartColumns, iendColumns);rnrange.EntireRow.Insert(iStartColumns, iendColumns); //这一句代码抛错!
NullReferenceException问题
string sknPath = "C:\\Documents and Settings\\Administrator\\Local Settings\\Temp\\vista1.ssk";rn FileInfo fi = new FileInfo(sknPath);rn if(!fi.Exists)rn rn Assembly asm = Assembly.GetExecutingAssembly();rn Stream strm = asm.GetManifestResourceStream("vista1");rn byte[] bytes = new byte[strm.Length];//这句出现异常rn strm.Read(bytes,0,(int)strm.Length);rn File.WriteAllBytes(sknPath,bytes);rn rnrnrn这个程序该怎么改啊
求助NullReferenceException
[code=C#]rn//string[] s = "","","","","","","";rn string[] s = null;rn lstSource.Items.CopyTo(s, 0);rn lstSource.Items.Clear();rn lstTarget.Items.AddRange(s);rn[/code]rnrn我写了一段2个LISTBOX互选的小代码,这是里面全部移动的一段,string[] s = null;这句老是报NullReferenceException,于是我改成string[] s = "","","","","","","";但是如果以后比如要是加了几项又要改代码了,有什么好办法吗?rn
未处理
1.在Android的框架层调用其它的App?如果熟悉Android源码的话在框架层调用其他App是可以的,类似于一个App调用另一App的实现思路: ``` Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER);
C#中for判断dataGridView1出现NullReferenceException异常
源代码如下,dataGridView1已打开Excel文件,并正确显示,现在用for判断内容并输出到textbox,去掉for可以正常显示:rnprivate void button2_Click(object sender, EventArgs e)rn rn for (int i = 0; i < this.dataGridView1.RowCount; i++)rn rn //if (dataGridView1[2, i].Value.ToString().Equals("555555"))rn //rnrn //textBox1.Text = dataGridView1[2, 2].Value.ToString();rn //rnrnrn if (this.dataGridView1.Rows[i].Cells[0].Value.ToString().Equals("555555"))rn rn textBox2.Text = dataGridView1[2, i].Value.ToString();rn rnrn rnrn调试时出现NullReferenceException异常 错误
c#下出现“”未处理System.BadImageFormatException“错误
出现这种情况的原因通常是在一个项目中引用了其他项目,而不同项目生成时的目标平台不同(32位和64位)
C# WinForm 捕获未处理的异常
C# WinForm 捕获<em>未处理</em>的异常
未处理ArgumentException 参数无效 C#
运行环境是VS2005rn代码如下:rn public partial class Form1 : Formrn rn public Form1()rn rn InitializeComponent();rn Bitmap myBitmap = new Bitmap("Spiral.png");rn rnrn rn第一次编译,很正常,没有发现问题。rn然后关掉程序,再次编译,就会对Bitmap myBitmap = new Bitmap("Spiral.png");这句弹出错误。rn<em>未处理</em>ArgumentException。参数无效。rnrn会是资源没有释放的关系吗?我只要把Bitmap那句删了重新打一遍就没事了,然后第二次编译依然出错。rnrn各位达人们可以帮我解释一下这奇怪的现象吗……rn
C#提示异常“未处理win32Exception”
用C#做打印功能调试的时候,点击打印按钮提示“<em>未处理</em>win32Exception”[img=http://57768.3e3e.info/111.gif][/img]这是截图,怎么解决啊,希望各位大侠帮忙!急~~
C# WinForm捕获未处理的异常
using System; using System.Collections.Generic; using System.Windows.Forms; using System.IO; namespace GobalException { static class Program { /// /// 应用程序的主入口点。 ///
C# 捕获未处理异常的问题
根据网上找到的资料,WPF下如果有我们自己未捕获的异常,可通过WPF的AppDomain.CurrentDomain.UnhandledException事件处理,单独写了一个测试代码如下:rnrn。。。。。。。。。。。。。。。。。。。。。。。。。。rnnamespace 未捕获异常处理rnrn /// rn /// Interaction logic for Window1.xamlrn /// rn public partial class Window1 : Windowrn rn DispatcherTimer timer = new DispatcherTimer();rn public Window1()rn rn InitializeComponent();rn rnrn private void button1_Click(object sender, RoutedEventArgs e)rn rn string s = "#ss";rn int a = Convert.ToInt32(s);rn rnrn private void Window_Loaded(object sender, RoutedEventArgs e)rn rn // Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(MyDispatcherUnhandledException);rn AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyUnhandledException);rnrn timer.Tick += new EventHandler(Timer_Tick);rn timer.Interval = TimeSpan.FromSeconds(2);rn timer.Start();rn rn private void Timer_Tick(object sender, EventArgs e)rn rn Grid gd = new Grid();rn MyFun(gd);rn rn private void MyFun(Grid gd)rn rn Uri uri = new Uri("D:\\a.jpg");rn ImageSource ims = new BitmapImage(uri);rn Image img = new Image();rn img.Source = ims;rn gd.Children.Add(img);rn rn private void MyUnhandledException(object sender, UnhandledExceptionEventArgs e)rn rn MessageBox.Show("MyUnhandledException"+e.ExceptionObject.ToString());rn rn private void MyDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)rn rn MessageBox.Show("MyDispatcherUnhandledException" + e.Exception.Message);rn rn rnrn在Timer的处理方法中有会产生异常的代码"D:\\a.jpg"图片实际不存在,通过上述的UnhandledException事件可以在程序崩溃前捕获该异常。rn======================================rn本人在目前实际项目中发生了一个目前未找到的异常,表现为运行一段时间后直接就崩溃了,未提示任何rn提示框或异常,所以按照上述方法进行未捕获的异常处理(UnhandledException事件的处理代码中将异常信息写入.txe文件和弹出提示框),但仍出现程序崩溃,还是未捕获到异常位置。rn(1)如果直接运行.exe程序(debug下的)出现异常时直接崩溃“消失”,但还是未捕获到异常信息。rn(2)如果加上源码调试运行,程序出现异常时会“卡死”,但不会消失,也不会提示异常信息。rn(3)DispatcherUnhandledException事件也试过,还是无法找到异常。rn希望各位提供下解决思路,或这上述方法使用不对的地方也请提出来,非常感谢哈!
C#中的未处理异常的拦截
C#中的<em>未处理</em>异常的拦截直接挂接Application.ThreadException(仅限WinForms,且只对UI线程有效)或者AppDomain.CurrentDomain.UnhandledException事件一般采用ThreadException方法,AppDomain的那个操作起来比较麻烦,因为同时受.net和操作系统监控,可能最终效果不理想。另外,不要两个同时使用,只有一
【转】NGUI创建UIRoot后报NullReferenceException的解决办法
本文参考自http://forum.china.unity3d.com/thread-1099-1-1.html 使用NGUI版本3.7.5。 在创建了一个UIRoot后,有时会报NullReferenceException的错误,如下图。虽然报错但是不影响运行。 截取部分报错输出是 [html]view plaincopy NullRef...
怎么解决NullReferenceException
#region Web Form Designer generated codern override protected void OnInit(EventArgs e)rn rn //rn // CODEGEN: This call is required by the ASP.NET Web Form Designer.rn //rn InitializeComponent();rn base.OnInit(e);rn rn rn /// rn /// Required method for Designer support - do not modifyrn /// the contents of this method with the code editor.rn /// rn private void InitializeComponent()rn rn this.TextBox2.TextChanged += new System.EventHandler(this.TextBox2_TextChanged);rn this.Button1.Click += new System.EventHandler(this.Button1_Click);rn this.rpt_Message.ItemCommand += new System.Web.UI.WebControls.RepeaterCommandEventHandler(this.Repeater1_ItemCommand);rn this.Load += new System.EventHandler(this.Page_Load);rnrn rn #endregionrnrn这些代码干什么用的啊?好像是自己生成的,为什么会报错呢?
在线等待:NullReferenceException异常?
我从UserControl派生自己的类:rnpublic class MyUserControl:System.Web.UI.UserControlrnrn protected MyClass mc;rnrn public MyUserControl() : base()rn rn mc = Application["MyClass"];rn // 执行这一句总是出现NullReferenceException异常 rn if (mc == null)rn rn mc = new MyClass();rn Application["MyClass"] = mc;rn rn rnrnrn分不多但可以马上给!rnrn
120急救,WP,NullReferenceException
总体描述,要实现的功能是一个网址收藏夹的功能,添加标题,简介和网址,将信息存储在独立存储空间,以“Collection”的形式。然后将独立存储空间中的数据绑定到页面“Pivot”的ListBox上,点击ListBox中的某一项,用浏览器打开相应的网址。rnrn1、添加的过程(这个没问题):rnif (!Collections.Favs.GetInstance().CheckExist(BodyTitle.Text,WebSite.Text))rn rn CollectionItem.FavsItem favsItem = new CollectionItem.FavsItem();rn favsItem.Title = BodyTitle.Text;rn favsItem.Intro = Intro.Text;rn favsItem.Address = WebSite.Text;rn rn Collections.Favs.GetInstance().Add(favsItem);rnrnrn //保存rn Collections.Favs.GetInstance().Save();rn MessageBox.Show("添加成功");rn this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));rn rn elsern rn MessageBox.Show("已存在");rn rn2、绑定的过程(这个也没问题)rn rn rn rn rn rn rn [color=#FF0000] [/color] rn rn rn rn rn rn3、被绑定的集合类rnpublic class FavsItem : INotifyPropertyChangedrn rn public string _title;rn public string Titlern rn get return _title; rn setrn rn _title = value;rn NotifyPropertyChanged("Title");rn rn rnrn public string _intro;rn public string Introrn rn get return _intro; rn setrn rn _intro = value;rn NotifyPropertyChanged("Intro");rn rn rnrn [color=#FF0000]public string _address;rn public string Addressrn rn get return _address; rn setrn rn _address = value;rn NotifyPropertyChanged("Address");rn rn rnrnrn public Uri Urlrnrngetrn return new Uri ("/BrowserPage.xaml?url="+Address,UriKind.Relative); rnrn[/color]rnrn public event PropertyChangedEventHandler PropertyChanged;rn private void NotifyPropertyChanged(string propertyName)rn rn if (null != PropertyChanged)rn rn PropertyChanged(this, new PropertyChangedEventArgs(propertyName));rn rn rn rnrn4、跳转到打开浏览器的页面rnpublic BrowserPage()rn rn InitializeComponent();rnrn if (NavigationContext.QueryString.Count > 0)rn[color=#FF0000]问题一:这一句提示异常,“NullReferenceException”,有点不明白在出来的路径中有参数啊,怎么会出现这样的异常???[/color]rn string url = NavigationContext.QueryString["url"];rn webBrowser1.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));rn rnrn[color=#FF0000]问题二:如果用"Loaded"事件应该怎样写,也是写在这里吗???[/color]rn rnrn另外,如果用静态变量传递Url参数,好像参数也为空。比如:public static class Favsrn rn public static string Address get; set; rn rn[color=#FF0000]难到是Address字段的值为空,可是添加的时候明明添加上了啊。。。不知道怎么回事,紧急求助。。。[/color]
NullReferenceException,就不应该存在!
如果要你说出 .NET 中的三个异常,NullReferenceException 一定会成为其中一个;如果说出 .NET 中的一个异常,NullReferenceException 也会被大多数人说出来。它让这么多人印象深刻,是因为它在项目中实在是太常见了,常见到每一个 C#/.NET 入门者必然会遇到。然而,这个异常本不应该存在!
NullReferenceException,System.Data.OleDb.OleDbException: 未指定的错误
大家救救我啊,我的程序怎么会出现这个错误啊?。。。。。我用的是access 数据库rn还有我的页面怎么刷新后都会发生NullReferenceException这个列外呢rnrn“/”应用程序中的服务器错误。rn--------------------------------------------------------------------------------rnrn未指定的错误 rn说明: 执行当前 Web 请求期间,出现<em>未处理</em>的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误rnrn源错误: rnrn执行当前 Web 请求期间生成了<em>未处理</em>的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 rnrn堆栈跟踪: rnrnrn[OleDbException (0x80004005): 未指定的错误]rn System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1131233rn System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +53rn System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27rn System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +47rn System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105rn System.Data.OleDb.OleDbConnection.Open() +37rn zkd.zkdOledbHelper.OleDBHelper.PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, CommandType cmdType, String cmdText, OleDbParameter[] cmdParms) in F:\xtlsolution\OledbHelper\OleDBHelper.cs:244rn zkd.zkdOledbHelper.OleDBHelper.ExcuteDataSet(OleDbConnection conn, CommandType cmdType, String cmdText, OleDbParameter[] cmdParms) in F:\xtlsolution\OledbHelper\OleDBHelper.cs:183rn zkd.zkdOledbHelper.product1Dal.Viewproduct1List(Int32 pageSize, Int32 toPage, Int32& recordCount) in F:\xtlsolution\OledbHelper\product1Dal.cs:238rn myascx_gcal.product1ListtBind() +150rn myascx_gcal.Page_Load(Object sender, EventArgs e) +21rn System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15rn System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33rn System.Web.UI.Control.OnLoad(EventArgs e) +99rn System.Web.UI.Control.LoadRecursive() +47rn System.Web.UI.Control.LoadRecursive() +131rn System.Web.UI.Control.LoadRecursive() +131rn System.Web.UI.Control.LoadRecursive() +131rn System.Web.UI.Control.LoadRecursive() +131rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436rnrn rnrnrn--------------------------------------------------------------------------------rn版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; ASP.NET 版本:2.0.50727.1433
microphone.BufferReady事件绑定异常NullReferenceException
[img=https://img-bbs.csdn.net/upload/201408/12/1407813947_355720.png][/img]rn请问这是什么原因?该怎么解决啊?新手求助~~
求助:关于多线程 NullReferenceException
private void button1_Click(object sender, System.EventArgs e)rn rn ThreadStart tsWorkTread1 = new ThreadStart( Display );rn Thread tThread1 = new Thread( tsWorkTread1 );rn tThread1.Name = "thread 1 :";rn tThread1.IsBackground = true;rn tThread1.Start();rn rn ThreadStart tsWorkTread2 = new ThreadStart( Display );rn Thread tThread2 = new Thread( tsWorkTread2 );rn tThread2.Name = "thread 2 :";rn tThread2.IsBackground = true;rn tThread2.Start();rn rnprivate void Display()rn rn Thread tCurrentThread = Thread.CurrentThread;rn for( int i = 0; i < 1000; i++ )rn rn this.richTextBox1.Text += tCurrentThread.Name + i.ToString() + "\n";rn rn rnrn private System.Windows.Forms.RichTextBox richTextBox1;rnrn上述例子为什么会抛出NullReferenceException 呢?rn有什么解决办法呢?rn谢谢各位!rn
NullReferenceException是啥?
我用vb.net写了一个关于DirectDraw的DLLrn然后写了另外一个程序去调用这个dllrn在这个程序中 我用Dim direct As New MyDirectDraw.DrawMain()rn而且我在DrawMain类的New里加了Beep()rn在启动时的确可以听到声音rnrn但是当我在一个Button2_Click里调用DrawMain里的一个函数时 出现:rnrn<em>未处理</em>的“System.NullReferenceException”类型的异常出现在 microsoft.directx.directdraw.dll 中rn其他信息:未将对象引用设置到对象的实例。rnrn这是啥东西?rnrn还有 在编写vb的类库的时候如何调试阿?我的确设置了调试外部程序 rn但是调试的时候 它给我看的都是汇编。。。 我差一点没有昏过去rn一个编vb的人 用的着汇编马!rnrn
mysql连接器的抛NullReferenceException
大家好,不知道有没有人遇到下面同样的异常,从代码来看应该是command执行超时后请求cancelquery过程中抛的异常rnrnEvent:1003rnMessage:System.NullReferenceException: Object reference not set to an instance of an object.rn at MySql.Data.MySqlClient.MySqlConnection.get_ServerThread()rn at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exception ex)rn at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)rn at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)rn
NullReferenceException怎么解决
if (System.Web.HttpContext.Current.Session["user_inf"] != null )rn这句调试的时候出现了错误,帮忙看看,谢谢rn错误类型是rn<em>未处理</em>的System.NullReferenceException ,未将对象引用设置到对象的实例。
NullReferenceException这是什么异常
[public bool CheckExist(string Title)rn rn bool isExist = false;rn [color=#FF0000] foreach (var passItem in PassCollections)rn问题:这里出现异常“NullReferenceException”,异常的名字叫做“NullReferenceException was handle。”请问这是什么异常,一般是在那种情况下触发???rn[/color] rn if (passItem.Title == Title)rn rn isExist = true;rn break;rn rn rnrn return isExist;rn rnrn该页全部代码:rnusing System.Collections.ObjectModel;rnusing System.IO.IsolatedStorage;rnrnnamespace WPPA.Collectionsrnrn public class Passrn rn private Pass()rn rn PassCollections = new ObservableCollection();rn if (IsolatedStorageSettings.ApplicationSettings.Contains("Pass"))rn PassCollections = IsolatedStorageSettings.ApplicationSettings["Pass"] as ObservableCollection; rn rnrn private static Pass _instance;rn public static Pass GetInstance()rn rn if (_instance == null)rn _instance = new Pass();rn return _instance;rn rnrnrn private ObservableCollection _passcollections;rn public ObservableCollection PassCollectionsrn rn get return _passcollections; rn set _passcollections = value; rn rnrn [color=#FF0000] public bool CheckExist(string Title)rn rn bool isExist = false;rn foreach (var passItem in PassCollections)rn rn if (passItem.Title == Title)rn rn isExist = true;rn break;rn rn rnrn return isExist;rn [/color] public void Add(CollectionItem.PassItem passItem)rn rn PassCollections.Add(passItem);rn rnrn public void Save()rn rn IsolatedStorageSettings.ApplicationSettings["Pass"] = PassCollections;rn IsolatedStorageSettings.ApplicationSettings.Save();rn rn rnrnrnrn
NullReferenceException 这是怎么回事
[code=csharp]using UnityEngine;rnusing System.Collections;rnrnpublic class tan : MonoBehaviour rn rn //施加普通力的对象rn GameObject addFrceObj = null;rn //施加目标位置力的对象rn GameObject addPosObj = null;rn //目标对象rn GameObject cubeObj = null;rn // Use this for initializationrn void Start () rn //获取施加普通力的对象rn addFrceObj = GameObject.Find ("Sphere0");rn //获取施加目标位置力的对象rn addPosObj = GameObject.Find ("Sphere1");rn //获取目标对象rn cubeObj = GameObject.Find ("Cube");rn rn void OnGUI()rn rn if(GUILayout.Button ("普通力",GUILayout.Height (50)))rn rn //施加一个力,X轴为100,y轴为1000rn addFrceObj.rigidbody.AddForce (10, 0, 10);rn rn if(GUILayout.Button ("位置力",GUILayout.Height (50)))rn rn //施加一个力,力会想这个方向移动,力的模式为冲击力rn Vector3 frce = cubeObj.transform.position - addPosObj.transform.position;rn addFrceObj.rigidbody.AddForceAtPosition (frce,addPosObj.transform.position,ForceMode.Impulse);rn rn rn // Update is called once per framern void Update () rn rn rnrn[/code]rnrn点击按钮就退出rn提示:NullReferenceExceptionrntan.OnGUI () (at Assets/tan.cs:26)rn这是怎么回事
关于NullReferenceException的问题
小弟想做一个登陆窗体,如果密码和用户名捕捉正确就转到另外一个窗体上,我用了一个html文件做为start page,但是在登陆是出先了NullReferenceExcpetionwasunhandledbyusercode的warning,请哪位高手能帮小弟解决一下这个问题,谢谢了rn代码如下rnrnusing System;rnusing System.Data;rnusing System.Configuration;rnusing System.Web;rnusing System.Web.Security;rnusing System.Web.UI;rnusing System.Web.UI.WebControls;rnusing System.Web.UI.WebControls.WebParts;rnusing System.Web.UI.HtmlControls;rnrnpublic partial class _Default : System.Web.UI.Page rnrn protected void Page_Load(object sender, EventArgs e)rn rn string username = Request.Form.Get("userNametxt").ToString();rn string password = Request.Form.Get("passwordtxt").ToString();rn Response.Redirect("Default2.aspx");rn rnrnrnhtml网页的html代码如下:rnrnrnrn Untitled Pagernrnrn rn rn rn rn Usernamern rn rn rn rn rn rn rn Passwordrn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnrn
DataTable.Columns.Add()时,提示“未处理NullReferenceException,未将对象引用设置到对象实例”~求指导,急~
private void button1_Click(object sender, EventArgs e)rn rn DataTable dt = new DataTable();rn dt = null;rn DataRow dr = null;rn for (int i = 0; i < lv1.Columns.Count; i++)rn rn dt.Columns.Add(lv1.Columns[i].Text, typeof(string));rn rn运行时提示“<em>未处理</em>NullReferenceException,未将对象引用设置到对象实例”rn拜托了~急~~
机房重构(C#)--未处理TypeLoadException(factory层问题)
问题图片: 问题来源: factory层出现问题,主要原因是因为代码不理解,写错了位置。 factory的以下三种写法:原理相同 //接受来自配置文件的数据 string StrDB = System.Configuration.ConfigurationManager.AppSettings[&amp;amp;amp;quot;DB&amp;amp;amp;quot;]; //用于连接配置文件并调取 ...
关于 用户代码未处理的提问aspnet (c#)
Sda.SelectCommand = new SqlCommand();rn Sda.SelectCommand.Connection = conn;rn Sda.SelectCommand.CommandText = "qq";rn Sda.SelectCommand.CommandType = CommandType.StoredProcedure;rn Sda.SelectCommand.Parameters.Add(new SqlParameter("@FDATE", SqlDbType.DateTime)).Value = quaryDate;rn Sda.Fill(Ds, "qq");rn DataTable newTb = new DataTable();rn for (int i = 0; i < Ds.Tables["qq"].Rows.Count; i++)rn rn DataRow newDatarow = newTb.NewRow();rnrn for (int j = 0; j < Ds.Tables["qq"].Columns.Count; j++)rn rn if (Ds.Tables["qq"].Columns[j].ColumnName.ToUpper() == "A001")rn [color=#FF0000]newDatarow[j] = Ds.Tables["qq"].Rows[i][j].ToString() + "%";[/color] rn rn DataList1.DataSource = newTb.DefaultView;rn DataList1.DataBind();rn在执行红色部分的时候报错:用户代码<em>未处理</em> indexoutofrangeexception 无法找到2 其中 row=7,column=18 为什么找不到2 rn请高手指教,谢谢 rn
关于C#中出现未处理NotImplementedException处理方法
我在<em>c#</em>窗体应用程序中运行程序时出现“<em>未处理</em>NotImplementedException未实现该方法或操作”异常,请问怎样解决 ?
未处理的异常
在某一个项目中,一开始没出现这个错误,后来过了一年后,再运行这个程序的时候,总是报堆栈溢出的错误。经过好几天的折腾,配置环境,调整视频格式,终于发现,其实是有一行代码的内存过大,所以才会溢出,遇到此类问题的时候,一定要仔细排查整个项目中所有的和内存相关的代码。因为在这个项目中,在函数的第一句就报错了,误导了我们,让我们以为是opencv封装的函数的问题,其实是这个函数中的某一句话出现了问题。。。为...
未处理 ing...
girdview 分页PageIndexChanging事件问题 昨天弄了一下午,总是提示激发了<em>未处理</em>的事件“PageIndexChanging“ 修改方法:一要在girdview 后面加 OnPageIndexChanging="GridView1_PageIndexChanging 二要cs页面中添加 protected void GridV...
未处理 CrossThreadMessagingException
C# 回调函数时出错rnrnfrmMain.AlarmFunc = new IMOSSDK.SDKCallBackFunc(frmMain.AlarmCallBackFunc);rn ulRet = IMOSSDK.IMOS_RegCallBackPrcFunc(ref IMOSSDK.stLoginInfo.stUserLoginIDInfo, frmMain.AlarmFunc);rnrnrn public void AlarmCallBackFunc(ulong ulProcType, IntPtr pParam)rn rn //Update();rn tryrn rn if (this.InvokeRequired)rn rn IMOSSDK.SDKCallBackFunc me = new IMOSSDK.SDKCallBackFunc(AlarmCallBackFunc);rn this.BeginInvoke(me, ulProcType, pParam);rn return;rn rn elsern //showlog("告警");rn IMOS_SDK.SDK.AS_ALARMPUSH_UI_S pstAlarmPush;rnrn if (null == pParam)rn rn //logrn return;rn rnrn tryrn rn switch ((IMOS_SDK.SDK.tagCallBackProcType)ulProcType)rn rn case IMOS_SDK.SDK.tagCallBackProcType.PROC_TYPE_DEV_STATUS: //设备状态,对应结构 : AS_STAPUSH_UI_Srn break;rn case IMOS_SDK.SDK.tagCallBackProcType.PROC_TYPE_ALARM: //告警,对应结构 : AS_ALARMPUSH_UI_S rn //pstAlarmPush = (IMOS_SDK.SDK.AS_ALARMPUSH_UI_S)Marshal.PtrToStructure(pParam, typeof(IMOS_SDK.SDK.AS_ALARMPUSH_UI_S));rn //pstAlarmPush = (IMOS_SDK.SDK.AS_ALARMPUSH_UI_S)pParam;rn //AlarmDAL.AddAlarmLog(ref pstAlarmPush, this);rn break;rn default:rn break;rn rn rn catch (Exception ex)rn rn showlog(ex.Message);rn rn rn rn catch (Exception ex)rn rn MessageBox.Show(ex.Message);rn rnrn
未处理DBConcurrencyException
vs2005提示我:rn<em>未处理</em>DBConcurrencyExceptionrn违反并发性: UpdateCommand 影响了预期 1 条记录中的 0 条。rnrn问题代码(<em>c#</em>):da.Update(ds, "xuanke");rn我在dataGridView中修改数据源为主键的数据时出现这种错误的,但修改其他非主键值时没问题,请问诸位是哪儿的问题?
未处理SqlException
文件一:主要是进行数据库的链接rnclass Mymeansrn rn public static SqlConnection My_con;rn public static string Login_ID = "";rn public static string Login_Name = "";rn public static string M_str_sqlcon = "Data Source=.;Database=db_PWMS;User id=;Pwd= ";rn public static int Login_n = 0;rn public static string AllSql = "Select * From 职工基本信息";rn rnrn public static SqlConnection getcon()rn rn My_con = new SqlConnection(M_str_sqlcon);rn My_con.Open();rn return My_con;rn rnrn public void con_close()rn rn if (My_con.State == ConnectionState.Open)rn rn My_con.Close();rn My_con.Dispose();rn rn rnrn public SqlDataReader getcom(string SQLstr)rn rn getcon();rn SqlCommand My_com = My_con.CreateCommand();rn My_com.CommandText = SQLstr;rn SqlDataReader My_read = My_com.ExecuteReader();rn return My_read;rn rnrn public void getsqlcom(string SQLstr)rn rn getcon();rn SqlCommand SQLcom = new SqlCommand(SQLstr,My_con);rn SQLcom.ExecuteNonQuery();rn SQLcom.Dispose();rn con_close();rn rnrn public DataSet getDataSet(string SQLstr, string tableName)rn rn getcon();rn SqlDataAdapter SQLda = new SqlDataAdapter(SQLstr, My_con);rn DataSet My_DataSet = new DataSet();rn SQLda.Fill(My_DataSet, tableName);rn con_close();rn return My_DataSet;rn rnrnrnrn文件二:一些公共类的设计rnclass MyModulern rn PMS.Mymeans MyDataClass =new PMS.Mymeans();rn public static string ADDs="";rn public static string FindValue = "";rn public static string Address_ID="";rn public static string User_ID ="";rn public static string User_Name="";rnrn public void Show_Form(string FrmName, int n)rn rn if (n == 1)rn rn if (FrmName == "人事档案管理")rn rn PMS.F_MainFile FrmManFile = new F_MainFile();rn FrmManFile.Text = "人事档案管理";rn FrmManFile.ShowDialog();rn FrmManFile.Dispose();rn rnrn rn rnrn public void Clear_Control(Control.ControlCollection Con)rn rn foreach (Control C in Con)rn rn if (C.GetType().Name == "TextBox")rn if (((TextBox)C).Visible == true)rn ((TextBox)C).Clear();rn if (C.GetType().Name == "MaskedTextBox")rn if (((MaskedTextBox)C).Visible == true)rn ((MaskedTextBox)C).Clear();rn if (C.GetType().Name == "ComboBox")rn if (((ComboBox)C).Visible == true)rn ((ComboBox)C).Text="";rn if (C.GetType().Name == "PictureBox")rn if (((PictureBox)C).Visible == true)rn ((PictureBox)C).Text="";rnrn rn rnrn public string GetAutocoding(string TableName, string ID)rn rn SqlDataReader MyDR = MyDataClass.getcom("select max(" + ID + ")NID from " + TableName);rn int Num = 0;rn if (MyDR.HasRows)rn rn MyDR.Read();rn if (MyDR[0].ToString() == "")rn return "0001";rn Num = Convert.ToInt32(MyDR[0].ToString());rn ++Num;rn string s = string.Format("0:0000", Num);rn return s;rn rn elsern rn return "0001";rn rn rnrn public void Ena_Button(Button B1, Button B2, Button B3, Button B4, int n1, int n2, int n3, int n4)rn rn B1.Enabled = Convert.ToBoolean(n1);rn B2.Enabled = Convert.ToBoolean(n2);rn B3.Enabled = Convert.ToBoolean(n3);rn B4.Enabled = Convert.ToBoolean(n4);rn rn rnrnrn文件三:在窗口中单击“添加”按钮时,则首先会调用Clear_Control方法,将指定控件集下的控件进行清空,然后根据表名和ID字段调用GetAutocoding方法进行自动编号。rnrn public partial class F_MainFile : Formrn rn public F_MainFile()rn rn InitializeComponent();rn rnrn PMS.Mymeans MyDataClass = new PMS.Mymeans();rn PMS.MyModule MyMC = new PMS.MyModule();rn public static DataSet MyDS_Grid;rn public static string tem_Field = "";rn public static string tem_Value = "";rn public static string tem_ID = "";rn public static int hold_n = 0;rn public static byte[] imgBytesIn; //用来存储图片的二进制数rn public static int Ima_n = 0; //判断是否对图片进行了操作rn public static string Part_ID = ""; //存储数据表的ID信息rnrn private void Sut_Add_Click(object sender, EventArgs e)rn rn MyMC.Clear_Control(tabControl1.TabPages[0].Controls);rn S_0.Text = MyMC.GetAutocoding("职工基本信息", "职工编号");rn hold_n = 1;rn MyMC.Ena_Button(Sut_Add, Sut_Amend, Sut_Cancel, Sut_Save, 0, 0, 1, 1);rn groupBox5.Text = "当前正在添加信息";rn Img_Clear.Enabled = true;rn Img_Save.Enabled = true;rnrn rnrnrnrn文件四:数据库内容rn数据库名为db_PWMSrn其中的一个表,名为:职工基本信息rn此表内容为:rn列名 数据类型rn职工编号 varchar(5)rn职工姓名 varchar(20)rnrnrn进行调试rn当单击“添加”按钮时rn会出现以下错误:rn<em>未处理</em>SqlExceptionrn‘ ‘附件有语法错误rnrn此时错误的箭头会指向以下数据库链接语句的黄色处rn public SqlDataReader getcom(string SQLstr)rn rn getcon();rn SqlCommand My_com = My_con.CreateCommand();rn My_com.CommandText = SQLstr;rn SqlDataReader My_read = My_com.ExecuteReader();rn return My_read;rn rnrn如何去解决这个问题呢?rn
未处理 System.Runtime.Remoting.RemotingException?
<em>未处理</em> System.Runtime.Remoting.RemotingExceptionrn Message="无法加载类型“zhl.Person, Person, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”。"rn下面是Person类:rnnamespace zhlrnrn public class Person:MarshalByRefObjectrn rn private string m_name;rnrn public string Namern rn getrn rn return this.m_name;rn rn setrn rn this.m_name = value;rn rn rn public string SayHello()rn rn Console.WriteLine("Hello,my name is 0",m_name);rn return "Hi," + m_name;rn rn rnrn然后是客户端调用:rnrnrn rn rn rn rn rn rn rn rn rn rnrnrnusing System;rnusing System.Runtime.Remoting;rnrnnamespace zhlrnrn class ActiveClientrn rn static void Main(string[] args)rn rn RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);rnrn Person p = new Person();rn p.Name = "zhao hongliang";rn p.SayHello();rn Console.WriteLine("Press enter to exit.");rn Console.ReadLine();rn rn rnrnrn服务器端调用:rnrnrn rn rn rn rn rn rn rn rn rn rnrnrnusing System;rnusing System.Runtime.Remoting;rnrnnamespace zhlrnrn class ActiveServerrn rn static void Main(string[] args)rn rn RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);rn Console.WriteLine("Press enter to exit");rn Console.ReadLine();rn rn rnrn快疯掉了 找不到错误~!
未处理 System.Data.SqlClient.SqlException
小弟调试网上下载的程序出了问题了 但是除了这个问题rn<em>未处理</em> System.Data.SqlClient.SqlExceptionrn部分代码:rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.Data.SqlClient;rnrnrnnamespace 实验室设备管理系统rnrn public partial class 登录 : Formrn rn public static string name;rn public static string password;rn public static string entry;rn public 登录()rn rn InitializeComponent();rn rnrn private void label2_Click(object sender, EventArgs e)rn rnrn rnrn private void 登录_Load(object sender, EventArgs e)rn rn rn rnrn private void button1_Click(object sender, EventArgs e)rn rn rn if (this.textBox1.Text == "" || this.textBox2.Text == "")rn MessageBox.Show("请输入用户名和密码");rn elsern rnrn SqlConnection con = new SqlConnection(); //创建连接rn con.ConnectionString = "server=(local);database=实验室设备;uid=sa;pwd=";rn con.Open();rn SqlCommand cmd = con.CreateCommand();rn cmd.CommandText ="select *from 登录";rn SqlDataReader dr = cmd.ExecuteReader();rn if (dr.Read())rn rn string power = dr[0].ToString();rn 主界面 main = new 主界面();rn main.Tag = this.FindForm();rn this.Visible = false;rn main.ShowDialog();rn this.Close();rnrn rnrn elsern rn MessageBox.Show("用户名或密码错误");rn rn con.Close();rnrn rn rnrn private void button2_Click(object sender, EventArgs e)rn rn this.Close();rn rnrn public void textBox1_TextChanged(object sender, EventArgs e)rn rn name = this.textBox1.Text;rn SqlConnection con = new SqlConnection(); //创建连接rn con.ConnectionString = "server=(local);database=实验室设备;uid=sa;pwd=";rn con.Open();rn SqlCommand cmd = con.CreateCommand();rn cmd.CommandText = "select 权限 from 登录 where 姓名='" + this.textBox1.Text + "'";rn SqlDataReader sqlread = cmd.ExecuteReader(CommandBehavior.CloseConnection);rn if (sqlread.Read())rn rn label4.Text = sqlread["权限"].ToString();rn entry =this.label4.Text.Trim();rn con.Close();rn rn rnrn public void textBox2_TextChanged(object sender, EventArgs e)rn rn password = this.textBox2.Text;rn rnrn private void label4_Click(object sender, EventArgs e)rn rnrn rnrn rnrn rn rnrn谁能帮我看看啊?
未处理 System.FormatException?
这句 fee_change_money = Convert.ToInt32(fee_real_money)-fee_f_money;rn<em>未处理</em> System.FormatException rn什么问题呢?如何纠正啊?rnrn[code=C#]rn private void list_post_Click(object sender, EventArgs e)rn rnsd_all_money = (int)(Math.Floor(sd_all_money / 300) * 4);rnif(sd_all_money>9)rnrnsd_all_money = 9;rnrn rnrnstring fee_real_money;rnint card_id,class_card_fee,fee_free_all_money;rnrnrnprivate void fee_sum_end_Click(object sender, EventArgs e)rn rn rn fee_free_all_money = (int)(class_card_fee + sd_all_money);rn if (fee_free_all_money > 16)rn rn fee_free_all_money = 16;rn rnfee_f_money = ((int)(Math.Floor(fee_all_time)) * 4 + rn(int)((fee_all_time * 60) % 60 > 15 ? 1 : 0) * 4) - fee_free_all_money;rn if (fee_f_money > 0)rn rn tb_fee_in_money.Text = fee_f_money.ToString();rn rn elsern rn tb_fee_in_money.Text = "免费";rn rn if (class_card_fee + sd_all_money > 0)rn rn tb_fee_free_money.Text = (class_card_fee + sd_all_money).ToString();rn rn elsern rn tb_fee_free_money.Text = "无减免费用";rn rn fee_must_money = (fee_all_time) * 4;rn fee_nofree_money.Text = fee_must_money.ToString();rn fee_real_money = tb_s_money.Text;rn fee_change_money = Convert.ToInt32(fee_real_money)-fee_f_money;rn tb_b_money.Text = fee_change_money.ToString();rnrnrn rn[/code]rnrn
C#中executeNonQuery 出现未处理OleDbException
access为2003,C#2008运行时,会在executeNonQuery 出现<em>未处理</em>OleDbException,提示内容为“索引或主关键字不能包含一个 空 (Null) 值”这应该怎么解决
C#中int32.parse未处理FormatException,怎么解决?
语句如下: rn string st ;rn st = "dfsf";rn System .Console .WriteLine ( Int32.Parse( st));rn 调试,出现<em>未处理</em>FormatException,怎么解决?
C# 自定义控件绘图 未处理 System.AccessViolationException异常
在自定义一个控件,绘图(DrawLine)的时候出现了System.AccessViolationException异常异常,如下 <em>未处理</em> System.AccessViolationException Message="尝试读取或写入受保护的内存。这通常指示其他内存已损坏。" Source="System.Drawing" StackTrace: 在 System.D
C#窗体连接数据库出现未处理SqlException解决办法
将界面的名称改成当前包含用户名和密码的那张数据表的名称即可对警告信息进行处理,一定要保证数据表里面的用户名及密码的信息保持一致,这样就可以成功连接数据库并且不再出现警告信息
C#未处理 System.Data.SqlClient.SqlException" ' ' 附近有语法错误。"
[color=#FF0000]下边是源码,其中最后一句提示错误,错误提示如标题所示[/color]rnusing System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.Data.SqlClient;rnrnnamespace MySchoolrnrn public partial class StudentLidtForm : Formrn rn DataSet dataSet = new DataSet("MySchool"); //创建DataSet对象rn SqlDataAdapter dataAdapter; //声明一个数据适配器rn public StudentLidtForm()rn rn InitializeComponent();rn rnrn private void StudentLidtForm_Load(object sender, EventArgs e)rn rn //查询用的SQL语句rn string sql = "SELECT SStudentId,SLoginId,SStudentName,SStudentNO,SSex,SPhone,SAddress,SWishWork FROM Students";rn //创建DataAdapter对象rn dataAdapter = new SqlDataAdapter(sql,DBHelper.connection);rn //填充数据集rn dataAdapter.Fill(dataSet,"Students");rn //指定DataGridView数据源,显示数据rn dataGridView1.DataSource = dataSet.Tables["Students"];rn rnrn private void btnUpdate_Click(object sender, EventArgs e)rn rn DialogResult result = MessageBox.Show("确定要保存修改吗?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);rn if (result == DialogResult.OK) //确认修改rn rn //自动生成更新数据用的命令rn SqlCommandBuilder buider = new SqlCommandBuilder(dataAdapter);rn //将修改过到底数据提交到数据库rn dataAdapter.Update(dataSet,"Students");rn rn rnrn private void btnClose_Click(object sender, EventArgs e)rn rn this.Close();rn rn //刷新rn private void btnRenovate_Click(object sender, EventArgs e)rn rn dataSet.Tables["Students"].Clear();rnrn //查询用的SQL语句rn string sql = "SELECT SStudentId,SLoginId,SStudentName,SStudentNO,SSex,SPhone,SAddress,SWishWork FROM Students";rn //创建DataAdapter对象rn dataAdapter = new SqlDataAdapter(sql, DBHelper.connection);rn //填充数据集rn dataAdapter.Fill(dataSet, "Students");rn //指定DataGridView数据源,显示数据rn dataGridView1.DataSource = dataSet.Tables["Students"];rn rnrn private void btnChoice_Click(object sender, EventArgs e)rn rn //基本SQL语句rn string sql = "SELECT SStudentId,SLoginId,SStudentName,SStudentNO,SSex,SPhone,SAddress,SWishWork FROM Students";rn //根据组合框选择组合SQL语句rn switch (cboChoices.Text)rn rn case "男": //增加性别为男的条件rn sql += " WHERE SSex='男'";rn break;rn case "女": //增加性别为女的条件rn sql += " WHERE SSex='女'";rn break;rn default:rn break; //不做任何操作rn rnrn //清空表中原有的数据rn dataSet.Tables["Students"].Clear();rn //重新指定DataAdapter对象的查询语句rn dataAdapter.SelectCommand.CommandText = sql;rn //重新填充数据集rn [color=#FF0000]dataAdapter.Fill(dataSet,"Students"); //此处提示错误[/color]rn rn rn
未处理的知识点
1. private —Methods defined in the class can directly access the instance variables that follow, but subclasses cannot. 该类中的方法可以访问这样的变量,子类不可以。
未处理 Win32Exception
做的自动更新执行到rntryrn rn MessageBox.Show("检测到有新版本发布了,是否需要更新!", "信息提示", rnrnMessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);rn System.Diagnostics.Process.Start("update.exe", GlobParams.baseURL); rn this.Dispose();rn this.Close();rn rn catch(Exception ex)rn rn Debug.Writeline("升级失败了,原因是:" + ex.Message);rn rn这句执行不下去出现异常 System.Diagnostics.Process.Start("update.exe", GlobParams.baseURL); rn
未处理的 "System.IndexOutOfRangeException"
<em>未处理</em>的 "System.IndexOutOfRangeException" rnrn这句:int fee_card_flag =(Int32)( rs_check["car_park_fee.car_flag"]); rncar_park_fee.car_flag是int型默认值是0不允许为空rnrnrn[code=C#]rn private void fee_in_card_id_TextChanged(object sender, EventArgs e)rn rn string fee_check_card;rn if (fee_in_card_id.Text.Length == 10)rn rn card_id = fee_in_card_id.Text;rn fee_check_card = "select * from car_park_fee left join car_park_templist on car_park_fee.car_fee_nums = car_park_templist.temp_card_num where rndatediff(d,car_park_fee.car_fee_start,getdate())= 0 and car_park_fee.car_fee_nums rn= '" + card_id + "'and rncar_park_templist.temp_card_num is null ";rn SqlConnection conn_check = new SqlConnection(fee_conn.sql_conn());rn SqlCommand command_check = new SqlCommand(fee_check_card, conn_check);rn tryrn rn conn_check.Open();rn rn catch(System.Exception sqler)rn rn MessageBox.Show("数据库连接错误!", sqler.Message, MessageBoxButtons.OK, rnMessageBoxIcon.Error);rn return;rn rn SqlDataReader rs_check = command_check.ExecuteReader();rn while (rs_check.Read())rn rn rn int fee_card_flag =(Int32)( rs_check["car_park_fee.car_flag"]);rnMessageBox.Show("此会员卡今天已经停过车了", fee_card_flag.ToString(), rnMessageBoxButtons.OK, MessageBoxIcon.Error);rn return;rn rn rs_check.Close();rn conn_check.Close();rn rn [/code]
未处理的异常???
在d3d编程的时候 最经常出现 <em>未处理</em>的异常 读取位置冲突 还是运行时候的错误 我调试起来很费劲rn麻烦问一下 这个错误一般的都怎么引起的??
未处理IOException
我想打开form窗体时,显示上一次textbox里面的值!!简单的测试下,还是有错误.大家帮我看下rn<em>未处理</em>Ioexception ;rn文件“D:\My Documents\Visual Studio 2005\Projects\WindowsApplication85\WindowsApplication85\bin\Debug\fs.txt”正由另一进程使用,因此该进程无法访问该文件。rnrnrnform窗体上就就一个textbox.别的控件都没有!!代码如下rn[code=C#]using System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.IO;rnusing System.Threading;rnnamespace WindowsApplication85rnrn public partial class Form1 : Formrn rn public Form1()rn rn InitializeComponent();rn rnrn private void Form1_Load(object sender, EventArgs e)rn rn FileStream fs = new FileStream("fs.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);rn StreamReader sr = new StreamReader(fs);rn this.textBox1.Text = sr.ReadToEnd();rn fs.Close();rn sr.Close();rn rnrn private void textBox1_TextChanged(object sender, EventArgs e)rn rn rn FileStream fs = new FileStream("fs.txt", FileMode.Truncate, FileAccess.ReadWrite);rn StreamWriter sw = new StreamWriter(fs);rn sw.Write(this.textBox1.Text, Encoding.Default);rn sw.Close();rn fs.Close();rn rn rn rn[/code]
未处理argumentoutofrangeexception
[img=https://img-bbs.csdn.net/upload/201706/02/1496382103_242838.jpg][/img]
未处理DIRECTORYNOTFOUNDEXCEPTION
如图:rn[img=https://img-bbs.csdn.net/upload/201311/17/1384671984_274681.png][/img]rnrn有关代码如下:rn[code=csharp]using System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.IO;rnusing System.Collections;rnusing SHF_BT;rnusing SHF_DA;rnusing SHF_UI;rnrnrnnamespace MES64G08_111_UIrnrn public partial class uiMES64G08_111_CourseShow : SHF_UI.uiSHF_CourseBasern rn #region 局部变量rn private btSHFPage page;rn private btSHFPages pages;rn private btSHFUserLogin userLogin;rn private string path = Directory.GetCurrentDirectory() + "..\\..\\..\\..\\SHFDB\\Text\\";rnrn #endregionrnrn #region 构造函数rn public uiMES64G08_111_CourseShow()rn rn InitializeComponent();rn rn //从test调入时的构造函数rn public uiMES64G08_111_CourseShow(Form callForm, btSHFUserLogin callLog, btSHFPage callPage)rn : base(callForm, callLog)rn rn InitializeComponent();rn this.page = callPage;rn this.userLogin = callLog;rn pages = new btSHFPages();rn rn #endregionrnrn #region 窗口载入rn private void uiMES64G08_111_CourseShow_Load(object sender, EventArgs e)rn rnrn rn #endregionrnrn #region 在窗口中显示信息rn private void showInfo()//在窗口中显示教学信息rn rnrn string path1 = path + page.TextInfo;rn this.readFile(path1, this.richTextBox1);rn rn #endregionrnrn #region 读取文本文件的内容(文本文件编码方式:UTF-8)rn public void readFile(string path, RichTextBox richTextBox)rn rn richTextBox1.Clear();rn richTextBox1.SelectionAlignment = HorizontalAlignment.Left;rn richTextBox1.SelectionIndent = 20;rn richTextBox1.SelectionHangingIndent = -20;rn richTextBox1.Multiline = true;rn StreamReader din = File.OpenText(path);rn String str;rn ArrayList al = new ArrayList();rnrn while ((str = din.ReadLine()) != null)rn rn al.Add(str);rn rnrn foreach (string s in al)rn rn richTextBox1.SelectedText += s;rn richTextBox1.SelectedText += "\r\n";rn rn din.Close();rn rn #endregionrnrn #region 选择学习项目rnrn private void 卦型_Click(object sender, EventArgs e)rn rn page = pages.GetOne(2);rn showInfo();rn rnrn private void 来源_Click(object sender, EventArgs e)rn rn page = pages.GetOne(3);rn showInfo();rn rnrn private void 预示_Click(object sender, EventArgs e)rn rnrn rnrn private void 象彖_Click(object sender, EventArgs e)rn rn page = pages.GetOne(4);rn showInfo();rn rnrn private void 全卦内容_Click(object sender, EventArgs e)rn rnrn rnrn private void 含义_Click(object sender, EventArgs e)rn rn page = pages.GetOne(7);rn showInfo();rn rnrn private void 白话解释_Click(object sender, EventArgs e)rn rn page = pages.GetOne(6);rn showInfo();rn rnrn #endregionrn rnrn[/code]rn我把要读取的TXT文件也确实在路径下:rn[img=https://img-bbs.csdn.net/upload/201311/17/1384672139_77867.png][/img]rnrn所以这个报错是怎么回事..求大家帮助
C# IndexOf 报异常
不多说 直接上代码 rn if (!string.IsNullOrEmpty(m_str))rn rn if (GlobleDate.m_databuffUser.TagList.IndexOf(m_str) == -1) rn rn GlobleDate.m_databuffUser.TagList.Add(m_str); rn rn rn m_str = "";rn GlobleDate.userWaitor.Set(); //data资源 告诉界面可以进行更新 rnrnrnrn
Java事件监听器的四种实现方式下载
Java事件处理机制 - 事件监听器的四种实现方式 相关下载链接:[url=//download.csdn.net/download/wintys/834557?utm_source=bbsseo]//download.csdn.net/download/wintys/834557?utm_source=bbsseo[/url]
后台微信全自动打招呼bluestacks版本下载
后台微信全自动打招呼bluestacks版本 支持后台运行 鼠标无劫持版本 速度更快 线程更佳 相关下载链接:[url=//download.csdn.net/download/woheni0411/4751654?utm_source=bbsseo]//download.csdn.net/download/woheni0411/4751654?utm_source=bbsseo[/url]
数字卡销售源码下载
数字卡销售源码 数字卡销售源码 数字卡销售源码 数字卡销售源码 相关下载链接:[url=//download.csdn.net/download/f553686/4890280?utm_source=bbsseo]//download.csdn.net/download/f553686/4890280?utm_source=bbsseo[/url]
相关热词 c# gdi 占用内存 c#中遍历字典 c#控制台模拟dos c# 斜率 最小二乘法 c#进程延迟 c# mysql完整项目 c# grid 总行数 c# web浏览器插件 c# xml 生成xsd c# 操作sql视图
我们是很有底线的