TO lwg140811() :你就是想把数据库导入到EXCEL里。因为我没有你的数据库,我就用MSSQL的数据库NorthWind写了一个例子。你可以参考一下。using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.OleDb; using Excel; namespace WindowsApplication10 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) {
} private void button1_Click(object sender, EventArgs e) { string source = "Provider=SQLOLEDB; Data Source=(local);Initial Catalog=Northwind;User ID=CSharp; Password=csharp"; string select = "select * from Customers"; try { using (OleDbConnection conn = new OleDbConnection(source)) { conn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, conn); DataSet ds = new DataSet(); da.Fill(ds, "Customers"); this.Cursor = Cursors.WaitCursor; try { Excel.Application myExcel = new Excel.Application(); myExcel.Application.Workbooks.Add(true); myExcel.Visible = true; myExcel.Cells[1, 1] = "导入数据"; int aRow = 2; int aCol = 1; foreach (DataColumn col in ds.Tables["Customers"].Columns) { myExcel.Cells[aRow, aCol] = col.Caption; aCol++; } aRow = 3; foreach (DataRow row in ds.Tables["Customers"].Rows) { aCol = 1; foreach (DataColumn col in ds.Tables["Customers"].Columns) { myExcel.Cells[aRow, aCol] = row[col]; aCol++; } aRow++; } MessageBox.Show("导出成功! ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); if (!myExcel.Application.Workbooks["sheet1"].Saved) myExcel.Application.Workbooks["sheet1"].Save(); myExcel.Application.Workbooks.Close(); myExcel.Quit(); this.Cursor = Cursors.Arrow; } catch (Exception ex) { MessageBox.Show(ex.Message); } conn.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
TO imwjb(燕子的烟斗) :不好意思,没看明白你的问题。还有你的问题好象跟C#不是直接有联系。
TO liujb526(): 上面那个写给lwg140811() 的例子是从MSSQL导出到EXCEL,跟ACCESS导出没太大区别,只是改一下数据库。不知道能不能帮的上。
顶 虽然不用C# 友情帮LZ P一下
TO shabusha() : 当移动滚动条时 怎么知道滚动条 动了几格 不是几格的问题(格由象素多少来定),是移动了多少像素位置。用AutoScrollPosition这个属性就能知道移动了多少象素,再根据字体大小,来计算几格。
就是用你写的那个 private void toolStripButton4_Click(object sender, EventArgs e) //导出 { string source = "Provider=SQLOLEDB; Data Source=(local);Initial Catalog=Northwind;User ID=sa; Password=140811"; string select = "select * from Customers where customerid='TORTU'"; try { using (OleDbConnection conn = new OleDbConnection(source)) { conn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, conn); DataSet ds = new DataSet(); da.Fill(ds, "Customers"); this.Cursor = Cursors.WaitCursor; try { Excel.Application myExcel = new Excel.Application(); myExcel.Application.Workbooks.Add(true); myExcel.Visible = true; myExcel.Cells[1, 1] = "导入数据"; int aRow = 2; int aCol = 1; foreach (DataColumn col in ds.Tables["Customers"].Columns) { myExcel.Cells[aRow, aCol] = col.Caption; aCol++; } aRow = 3; foreach (DataRow row in ds.Tables["Customers"].Rows) { aCol = 1; foreach (DataColumn col in ds.Tables["Customers"].Columns) { myExcel.Cells[aRow, aCol] = row[col]; aCol++; } aRow++; } if (!myExcel.Application.Workbooks["sheet1"].Saved) myExcel.Application.Workbooks["sheet1"].Save(); myExcel.Application.Workbooks.Close(); myExcel.Quit(); this.Cursor = Cursors.Arrow; //MessageBox.Show("导出成功! ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception ex) { MessageBox.Show(ex.Message); } conn.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } 我所要做到就是当关闭EXCEL时询问一下是否保存,用你这个代码好象导出完后就保存在我的文档里面了,关闭也没有提示了。你试一下是不是一导出后就已经保存了。能不能做成当关闭EXCEL时询问是否保存。谢谢啦!
TO: tommy_ty() 你程序的问题出在 TextBox1.Font = new System.Drawing.Font("宋体", mysize);这里的mysize不能为0,可以改成 TextBox1.Font = new System.Drawing.Font("宋体", mysize+1); 即可。
TO: clementchen() 不是很明白你的意思。问题描述简单了点。也许说的是通过实现IDisposable接口,用户可以控制销毁的时间.然后在子类中调用GC.SuppressFinalize(this);来让.NET的垃圾收集器不要强制调用该子类的析构函数.把实现销毁的方法放在父类里,让子类继承下来调用。不过把你的作业也拿来让我做,有点过了。
TO Rock_318():还真没看懂你的问题。呵
TO wmf0708():就象你贴子后跟的,需要实例,具体点的。
int i = this.listBox1.Items.Count; tabpage = new System.Windows.Forms.TabPage[i]; dataGridView = new System.Windows.Forms.DataGridView[i]; bindingSource = new System.Windows.Forms.BindingSource[i]; for (int j = 0; j < i; j++) { tabpage[j] = new TabPage(); dataGridView[j] = new DataGridView(); bindingSource[j] = new BindingSource(); this.tabControl1.Controls.Add(tabpage[j]); tabpage[j].Text = this.listBox1.Items[j].ToString(); tabpage[j].Controls.Add(this.dataGridView[j]); dataGridView[j].DataSource = this.bindingSource[j]; dataGridView[j].Dock = System.Windows.Forms.DockStyle.Fill; dataGridView[j].AllowUserToAddRows = false; OracleConnection conn = new OracleConnection(Properties.Settings.Default.ConnectionString); OracleCommand cmd = new OracleCommand(); cmd.CommandText = "select * from test; cmd.Connection = conn; OracleDataAdapter adapter = new OracleDataAdapter(); adapter.SelectCommand = cmd; DataTable dt = new DataTable(); adapter.Fill(dt); bindingSource[j].DataSource = dt; 此时数据是不是已经fill到本地机器的内存里了?此时for (int jj = 0; jj < dataGridViewqq.Rows.Count; jj++){dataGridView[j].Rows[jj].Cells[18].Value =0}报错,dataGridViewqq.Rows.Count未实例化,咋搞?然后如何将改动后的数据保存到数据库?
TO cjocky (过路人):不好意思,我也是开始学C#,现在是2.0,木用过1.0. 帮不上你。
To cjocky(过路人) :如果你知道一个控件的名称,当然可以操控它。不管是不是动态的。普通控件可以:
for (int i = 0; i < Controls.Count; i++) { if (Controls[i].Name == "xxxxx") (Controls[i] as Button).Visible = false; }菜单项: for (int i = 0; i < menuStrip1.Items.Count; i++) { if (menuStrip1.Items[i].Name == "XXXXXX") menuStrip1.Items[i].Visible = false; }
TO picasson() :可能它中间有读到不满10个的。数据库里全是因为出错的异常跳出了,没加入到数据库。你最好跟踪一下看看实际数据。
http://community.csdn.net/Expert/TopicView1.asp?id=5321699
谢谢
http://community.csdn.net/Expert/topic/5316/5316117.xml?temp=.6501734
您无法在 Microsoft .NET 框架中实现全局挂钩。若要安装全局挂钩,挂钩必须有一个本机动态链接库 (DLL) 导出以便将其本身插入到另一个需要调入一个有效而且一致的函数的进程中。这需要一个 DLL 导出,而 .NET 框架不支持这一点。托管代码没有让函数指针具有统一的值这一概念,因为这些函数是动态构建的代理。”2.网上还有另外一段话"使用如下代码即可实现全局钩子:
IntPtr pInstance = Marshal.GetHINSTANCE( Assembly.GetExecutingAssembly().ManifestModule );
Win32API.SetWindowsHookEx( WH_MOUSE_LL,m_MouseHookProcedure, pInstance, 0 );"3.可以看出后者是把挂钩函数放在同一个程序集了。而不是一个DLL里。所以你的代码不成功是可能的。4.补充一点,标准的C# HOOK里都是采取委托的方式,而你的代码却是标准的WIN32方式。有些不妥。
http://community.csdn.net/Expert/topic/5308/5308479.xml?temp=.5267755
http://community.csdn.net/Expert/topic/5289/5289995.xml?temp=.2119562帮我解决这三个问题!1
一个人最好一次提一个问题,而且你的三个问题有两个跟C#没什么关系。所以我只回答你其中一个跟C#有关的问题:即进度条的问题。
其实你参考的例子已经写的很清楚了,既然还不明白,我就照着你参考的例子把它完整的写出来,你自己看一看。
创建两个FORM: Form1, Form2:Form1的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication8
{ public partial class Form1 : Form
{
private Form2 myProgressBar = null; private delegate bool IncreaseHandle(int nValue); private IncreaseHandle myIncrease = null; private void ShowProcessBar()
{
myProgressBar = new Form2(); myIncrease = new IncreaseHandle(myProgressBar.Increase);
myProgressBar.ShowDialog();
myProgressBar = null;
} private void ThreadFunc()
{
MethodInvoker mi = new MethodInvoker(ShowProcessBar);
this.BeginInvoke(mi);
Thread.Sleep(1000);
bool blnIncreased = false;
object objReturn = null;
do
{
Thread.Sleep(50);
objReturn = this.Invoke(this.myIncrease, new object[] { 2 });
blnIncreased = (bool)objReturn;
}
while (blnIncreased);
}
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
Thread thdSub = new Thread(new ThreadStart(ThreadFunc));
thdSub.Start(); }
}
}Form2的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication8
{
public partial class Form2 : Form
{
public bool Increase(int nValue)
{
if (nValue > 0)
{
if (prcBar.Value + nValue < prcBar.Maximum)
{
prcBar.Value += nValue;
return true;
}
else
{
prcBar.Value = prcBar.Maximum;
this.Close();
return false;
}
}
return false;
} public Form2()
{
InitializeComponent();
}
}
}如果你还不明白,那我就没则了。
http://community.csdn.net/Expert/topic/5322/5322237.xml?temp=.7222254
private void toolStripButton4_Click(object sender, EventArgs e) //导出
{
DataSet ds = new DataSet();
this.ds = this.link.SelectDataBase("SELECT IndexID,CodeName, LongName,Memo FROM branchinfo WHERE ParentIndexID = '1'", "yhb");
ds.Tables["yhb"].AcceptChanges();
this.Cursor = Cursors.WaitCursor;
Excel.Application myExcel = new Excel.Application();
myExcel.Application.Workbooks.Add(true);
myExcel.Visible = true;
myExcel.Cells[1, 1] = this.dataGrid1.CaptionText;
//Object Date[ds.Tables["yhb"].Rows.Count][ds.Tables["yhb"].Columns.Count];
//生成标题
for (int i = 0; i < ds.Tables["yhb"].Columns.Count; i++)
{
myExcel.Cells[2, i + 1] = ds.Tables["yhb"].Columns[i].Caption;
}
//填充数据
for (int i = 0; i < ds.Tables["yhb"].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables["yhb"].Columns.Count; j++)
{
if (ds.Tables["yhb"].Rows[i][j].GetType() == typeof(System.String))
{ myExcel.Cells[i + 3, j + 1] = "'" + ds.Tables["yhb"].Rows[i][j].ToString();
}
else
{
myExcel.Cells[i + 3, j + 1] = ds.Tables["yhb"].Rows[i][j].ToString();
}
}
} this.Cursor = Cursors.Default;
MessageBox.Show("导出成功! ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
http://community.csdn.net/Expert/TopicView3.asp?id=5322307
帮我看看这个怎么解决
怎样在 Winform 导入导出access数据库为execl和txt文本啊.
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
using Excel;
namespace WindowsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
string source = "Provider=SQLOLEDB; Data Source=(local);Initial Catalog=Northwind;User ID=CSharp; Password=csharp";
string select = "select * from Customers";
try
{
using (OleDbConnection conn = new OleDbConnection(source))
{
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(select, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Customers");
this.Cursor = Cursors.WaitCursor;
try
{ Excel.Application myExcel = new Excel.Application();
myExcel.Application.Workbooks.Add(true);
myExcel.Visible = true;
myExcel.Cells[1, 1] = "导入数据";
int aRow = 2;
int aCol = 1;
foreach (DataColumn col in ds.Tables["Customers"].Columns)
{
myExcel.Cells[aRow, aCol] = col.Caption;
aCol++;
} aRow = 3; foreach (DataRow row in ds.Tables["Customers"].Rows)
{
aCol = 1;
foreach (DataColumn col in ds.Tables["Customers"].Columns)
{
myExcel.Cells[aRow, aCol] = row[col];
aCol++; }
aRow++;
} MessageBox.Show("导出成功! ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
if (!myExcel.Application.Workbooks["sheet1"].Saved)
myExcel.Application.Workbooks["sheet1"].Save();
myExcel.Application.Workbooks.Close();
myExcel.Quit();
this.Cursor = Cursors.Arrow;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} }
}
}
不是几格的问题(格由象素多少来定),是移动了多少像素位置。用AutoScrollPosition这个属性就能知道移动了多少象素,再根据字体大小,来计算几格。
谢了
static int offset = 200;
int[] OffSets; private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < panel1.Controls.Count ; i++)
{
if (button1.Text == "下移")
{ OffSets[i] = panel1.Controls[i].Top;
panel1.Controls[i].Top -= offset; }
else
{
panel1.Controls[i].Top = OffSets[i];
}
}
if (button1.Text == "下移")
button1.Text = "复原";
else
button1.Text = "下移";
} 在Form_Load里分配OffSets
private void Form1_Load(object sender, EventArgs e)
{
OffSets = new int[panel1.Controls.Count];
button1.Text = "下移"; }这样就能达到你要的效果。
我原来定义了一个 private System.Data.DataTable da = new DataTable();
运行时出现下面的错误:
“DataTable”是“System.Data.DataTable”和“Excel.DataTable”之间的不明确的引用
不知道是为什么?麻烦楼主帮忙看一下,谢谢啦!
1. 在IIS5中,当一个请求到达后,IIS首先会确认是什么类型的资源请求。如果是静态的请求(比如HTML),不会使用外部模块。直接由IIS处理。而IIS在你的网页中发现脚本,但是返回的页面却不是正常的ASP.NET的返回途径。所以会什么都没显示。
2. 如果发现是aspx类型的请求,会转发给aspnet_isapi.dll来处理。aspnet_isapi.dll通过命名通道把请求传递给aspnet_wp.exe来处理asp.net的请求。
3. 所以你发现什么没显示,但是数据库变了。一个解决方法: 放到iframe里。
<html>
<body>
<iframe src=Count.aspx?find=226 width="100%" height="100%" scrolling="no" frameborder="0"></iframe>
</body>
</html>这样就能达到你的目的
不知道是为什么?
的意思是说这两个命名空间(System.Data和Excel)中都有DataTable类。而你的程序是直接用DataTable来写的。所以编译器无法识别你的DataTable是哪个命名空间的。你可以在你的DataTable前把命名空间都写上。比如都写成 System.Data.DataTable即可。
在visual studio 2003 c#.net中新创建一个窗体,加入一个文本框、一个水平滚动条和一个标签。步骤如下:
(1)设置Labell的Text属性为“字体大小”;
(2)水平滚动条的Minimum属性值为5,Maximum属性值为55;水平滚动条的LargeChange属性值为5,SmallChange属性值为1;
(3)添加程序代码如下:
private void HScrollBar1_Scroll(object sender, ScrolleventArgs e)
{
int mysize;
mysize = HScrollBar1.Value;
TextBox1.Font = new System.Drawing.Font("宋体", mysize);
}
按以上方法编写完后却无法生成,不能运行,请楼主帮解。以下为全部代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication3
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.HScrollBar hScrollBar1;
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.hScrollBar1 = new System.Windows.Forms.HScrollBar();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(32, 24);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(328, 112);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "TextBox1";
//
// hScrollBar1
//
this.hScrollBar1.LargeChange = 5;
this.hScrollBar1.Location = new System.Drawing.Point(32, 176);
this.hScrollBar1.Maximum = 55;
this.hScrollBar1.Minimum = 5;
this.hScrollBar1.Name = "hScrollBar1";
this.hScrollBar1.Size = new System.Drawing.Size(328, 16);
this.hScrollBar1.TabIndex = 1;
this.hScrollBar1.Value = 5;
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 152);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 16);
this.label1.TabIndex = 2;
this.label1.Text = "字体大小";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(392, 214);
this.Controls.Add(this.label1);
this.Controls.Add(this.hScrollBar1);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
} private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void HScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
int mysize;
mysize = HScrollBar1.Value;
TextBox1.Font = new System.Drawing.Font("宋体", mysize);
}
}
}
private void toolStripButton4_Click(object sender, EventArgs e) //导出
{
string source = "Provider=SQLOLEDB; Data Source=(local);Initial Catalog=Northwind;User ID=sa; Password=140811";
string select = "select * from Customers where customerid='TORTU'";
try
{
using (OleDbConnection conn = new OleDbConnection(source))
{
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(select, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Customers");
this.Cursor = Cursors.WaitCursor;
try
{ Excel.Application myExcel = new Excel.Application();
myExcel.Application.Workbooks.Add(true);
myExcel.Visible = true;
myExcel.Cells[1, 1] = "导入数据";
int aRow = 2;
int aCol = 1;
foreach (DataColumn col in ds.Tables["Customers"].Columns)
{
myExcel.Cells[aRow, aCol] = col.Caption;
aCol++;
} aRow = 3; foreach (DataRow row in ds.Tables["Customers"].Rows)
{
aCol = 1;
foreach (DataColumn col in ds.Tables["Customers"].Columns)
{
myExcel.Cells[aRow, aCol] = row[col];
aCol++;
}
aRow++;
} if (!myExcel.Application.Workbooks["sheet1"].Saved)
myExcel.Application.Workbooks["sheet1"].Save();
myExcel.Application.Workbooks.Close();
myExcel.Quit();
this.Cursor = Cursors.Arrow;
//MessageBox.Show("导出成功! ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我所要做到就是当关闭EXCEL时询问一下是否保存,用你这个代码好象导出完后就保存在我的文档里面了,关闭也没有提示了。你试一下是不是一导出后就已经保存了。能不能做成当关闭EXCEL时询问是否保存。谢谢啦!
TextBox1.Font = new System.Drawing.Font("宋体", mysize);这里的mysize不能为0,可以改成
TextBox1.Font = new System.Drawing.Font("宋体", mysize+1);
即可。
//if (!myExcel.Application.Workbooks["sheet1"].Saved)
// myExcel.Application.Workbooks["sheet1"].Save();
//myExcel.Application.Workbooks.Close();
//myExcel.Quit();
将程序代码改写如下后,可以生成了,但调试时拖动滚动条字体不能改变大小,真苦脑呀!盼着楼主明天能给予解答.
再次感谢!
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
} private void richTextBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
int mysize;
mysize = hScrollBar1.Value;
richTextBox1.Font = new System.Drawing.Font("宋体", mysize+1);
}
}
}
在里面加一句: this.label1.Font = new System.Drawing.Font("宋体", mysize+1);应该就可以了,如下:
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
int mysize;
mysize = hScrollBar1.Value;
richTextBox1.Font = new System.Drawing.Font("宋体", mysize+1);
this.label1.Font = new System.Drawing.Font("宋体", mysize+1);
}
上午出去玩,有问题留言,下午回来后看。
还有,好象有几位怀疑我是否真的是C#的初学者。呵,我也没什么好说的,只是我有其他语言的基础,学C#可能上手快一些。语言毕竟是相通的,只是需要一个熟悉语法的过程。还有,相对其他W32语言,C#已经精简很多了。只要再了解一些.NET平台的工作原理,基本上,一周多点上手是没什么问题,只需要些时间熟悉C#的特有的一些表示方式和方法。
TO haohaoxi() :你说的不能同步具体是什么? 每次响应事件的延迟很长?或是偶长偶短?首先谢谢你的回复 我在说明下 假设这个底层事件每1S 钟发出 事件1 事件2 事件3 ...参数string 为s1 s2 s3 s4现在我在UI端接收的话 这个顺序会是杂乱无序的 我在想会不会是UI端想更新显示事件1的时候 事件2又发生 那程序又会跳到事件处理函数开始处 这样就让UI显示无序了.就这个问题 如果底层不能更改 有什么好方法吗?
请教楼主,如何解决这个问题?
同学给我留的作业题帮我解决了:创建一个只能通过操作父类来销毁它的两个子类的方法。
哈哈 另外问一下 新手应该怎么学习啊 给我介绍几本书 现在感觉对面向对象还有些迷茫呢
如果可能加我的qq多指导指导我,好吗?
再次谢谢啦
比如:
1.给底层事件编号,比如利用发生的时间。
2.统一用一个事件调度程序来所有事件放到UI端的优先队列里。
2.在UI端建立优先队列来存放底层来的事件。每次从优先队列中取最早的事件出来跟已经处理的最后一个事件的编号比较,如果是下一个事件,那么就处理,如果不是,就等待。优先队列保证了当前取出的事件是最早的。
3.这样就能按次序来处理事件。不知道这个思路能不能帮上你。
http://community.csdn.net/Expert/topic/5323/5323509.xml?temp=.6429407
private void Button1_Click(object sender, System.EventArgs e)
{
string today=DateTime.Now.ToString("yyyyMMdd");
string addr="C:\\"+today+".txt"; //打开当天的文件
string s="",pro_id="",now_time="",now_date="",bad_ness="";
StreamReader str_read;
str_read=File.OpenText(addr);
if (pos==0)
{
int i=0;
for(;str_read!=null;i++)
{
s=str_read.ReadLine(); //读取一串数据
pro_id=s[0].ToString()+s[1].ToString();
now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
bad_ness=""+s[18];
if(s.Length>19)
{
int len=s.Length;
bad_ness+=s[len-1].ToString();
}
string con_instr="insert into [scantable] (proid,nowtime,nowdate,badness) values ('"+pro_id+"','"+now_time+"','"+now_date+"','"+bad_ness+"')";
operate_sqlserver(con_instr);
}
pos=i;
}
str_read.Close();
}未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 122: {
行 123: s=str_read.ReadLine(); //读取一串数据
行 124: pro_id=s[0].ToString()+s[1].ToString();
行 125: now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
行 126: now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
源文件: c:\inetpub\wwwroot\showdata\default.aspx.cs 行: 124
帮忙看一下,是什么问题,看了半天,没有搞定
不是很明白你的意思。问题描述简单了点。也许说的是通过实现IDisposable接口,用户可以控制销毁的时间.然后在子类中调用GC.SuppressFinalize(this);来让.NET的垃圾收集器不要强制调用该子类的析构函数.把实现销毁的方法放在父类里,让子类继承下来调用。不过把你的作业也拿来让我做,有点过了。
tabpage = new System.Windows.Forms.TabPage[i];
dataGridView = new System.Windows.Forms.DataGridView[i];
bindingSource = new System.Windows.Forms.BindingSource[i];
for (int j = 0; j < i; j++)
{
tabpage[j] = new TabPage();
dataGridView[j] = new DataGridView();
bindingSource[j] = new BindingSource();
this.tabControl1.Controls.Add(tabpage[j]);
tabpage[j].Text = this.listBox1.Items[j].ToString();
tabpage[j].Controls.Add(this.dataGridView[j]);
dataGridView[j].DataSource = this.bindingSource[j];
dataGridView[j].Dock = System.Windows.Forms.DockStyle.Fill;
dataGridView[j].AllowUserToAddRows = false;
OracleConnection conn = new OracleConnection(Properties.Settings.Default.ConnectionString);
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "select * from test;
cmd.Connection = conn;
OracleDataAdapter adapter = new OracleDataAdapter();
adapter.SelectCommand = cmd;
DataTable dt = new DataTable();
adapter.Fill(dt);
bindingSource[j].DataSource = dt;
此时数据是不是已经fill到本地机器的内存里了?此时for (int jj = 0; jj < dataGridViewqq.Rows.Count; jj++){dataGridView[j].Rows[jj].Cells[18].Value =0}报错,dataGridViewqq.Rows.Count未实例化,咋搞?然后如何将改动后的数据保存到数据库?
s=str_read.ReadLine(); //读取一串数据
行 124: pro_id=s[0].ToString()+s[1].ToString();
行 125: now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
行 126: now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
如果你读到的S没那么长,或是空的,哪来的S[0],S[1]....S[10]?
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace ShowData
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.DropDownList DropDownList4;
protected System.Web.UI.WebControls.DropDownList DropDownList5;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button5;
protected System.Web.UI.WebControls.Button Button4;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public static int look_index=0; //查找参数
public static int aa=0; // 标志页面页码的参数
public static int pos=0;
public static int find_data=0; //查找按钮索引
public static string value_info;
public string count_num="0"; private void operate_sqlserver(string tab)
{
SqlConnection con=new SqlConnection();
string str="server=localhost;uid=sa;pwd=;database=work";
con.ConnectionString=str;
SqlCommand sqlcmd= new SqlCommand(tab,con);
SqlDataAdapter da=new SqlDataAdapter(tab,con);
sqlcmd.Connection.Open();
sqlcmd.ExecuteNonQuery();
sqlcmd.Connection.Close();
} private DataSet view_data(string tab)
{
SqlConnection con=new SqlConnection();
string str="server=localhost;uid=sa;pwd=;database=work";
con.ConnectionString=str;
SqlDataAdapter da=new SqlDataAdapter(tab,con);
DataSet ds=new DataSet();
da.Fill(ds);
return(ds);
} //page_operate()函数的定义
private void page_operate(string index,System.Web.UI.WebControls.DataGrid tab)//分页
{
System.Web.UI.WebControls.Button up_page=Button2; //传递上一页按钮
System.Web.UI.WebControls.Button down_page=Button3; //传递下一页按钮
System.Web.UI.WebControls.DropDownList page_size=DropDownList5; //传递显示记录个数的下拉菜单
System.Web.UI.WebControls.DropDownList data_keys=DropDownList1; //传递查询条件的关键字的下拉菜单
System.Web.UI.WebControls.DropDownList jump_keys=DropDownList4; //跳转到按钮
System.Web.UI.WebControls.TextBox data_vlue=TextBox1; //传递文本框
System.Web.UI.WebControls.Label data_count=Label1; //传递查找记录的个数的标签
data_count.Text="";
//string strID,录入时间,接待台帐表.id as id from 接待台帐表,hotel,交办领导 where 拟住宾馆=hotel.id and 交办领导.id=接待台帐表.交办领导 ";
//int count_index=0;
//int size_page=(page_size.SelectedIndex+1)*10; //显示记录的个数
} private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string today=DateTime.Now.ToString("yyyyMMdd");
string addr="C:\\"+today+".txt"; //打开当天的文件
string pro_id="",now_time="",now_date="",bad_ness="";
StreamReader str_read;
str_read=File.OpenText(addr);
if (pos==0)
{
int i=0;
for(;str_read!=null;i++)
{
s=str_read.ReadLine(); //读取一串数据
pro_id=""+s[0]+s[1];
now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
bad_ness=""+s[18];
if(s.Length>19)
{
int len=s.Length;
bad_ness+=s[len-1].ToString();
}
string con_instr="insert into [scantable] (proid,nowtime,nowdate,badness) values('"+pro_id+"','"+now_time+"','"+now_date+"','"+bad_ness+"')";
operate_sqlserver(con_instr);
}
pos=i;
}
str_read.Close();
}
}
}
希望楼主解答,万分感谢。
for (int i = 0; i < Controls.Count; i++)
{
if (Controls[i].Name == "xxxxx")
(Controls[i] as Button).Visible = false;
}菜单项:
for (int i = 0; i < menuStrip1.Items.Count; i++)
{
if (menuStrip1.Items[i].Name == "XXXXXX")
menuStrip1.Items[i].Visible = false;
}
请帮个忙了!谢谢了!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 32);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 120);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(168, 24);
this.label2.TabIndex = 2;
this.label2.Text = "label2";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 168);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(248, 56);
this.label3.TabIndex = 3;
this.label3.Text = "label3";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 232);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(248, 23);
this.label4.TabIndex = 4;
this.label4.Text = "label4";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
string now_time=DateTime.Now.ToString("yyyyMMdd");
now_time+=".txt";
string ss;
ss="C:\\"+now_time;
StreamReader sr;
string s;
sr=File.OpenText(ss);
s=sr.ReadLine();
int aa=0;
string sss="";
if(s[19].ToString()!=null)
{
sss=s[0].ToString()+s[1].ToString()+s[2].ToString()+s[3].ToString()+s[19].ToString();
}
label1.Text=sss;
for(int i=0;s!=null;i++)
{
//label1.Text=sss;
label3.Text=s;
Console.WriteLine(s);
s=sr.ReadLine();
++aa;
sss=""+s[0]+s[1]+s[2]+s[3];
label2.Text=aa.ToString();
label2.Text=sss;
}
sr.Close(); }
}
}
上一个程序他写到数据库的数据是正确的,所以我才不解
麻烦楼主调试一下这个小程序,看一下
组名txtbox
组描述。。txtbox
查找txtbox
我先在点几查找后就出来原来的ID
怎么做啊,进行还原
我的问题,谢谢