初学编程,求教高手改错

yanbing9113 2011-07-06 01:24:10
编程遇到了很多难题,不知道该怎么修改,哪位高手帮忙看看哪里出现了问题。部分代码因字数问题省略了


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IWshRuntimeLibrary;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Data.OleDb;




namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

string strConnect = "Provider=Microsoft.Jet.OleDb.4.0;data source=Desk.mdb";
static int i , i1, i2 , i3 , i4 , i5 ;
string[] lnk = new string[50];
string[] path = new string[50];
Button[] myButton = new Button[50];

private void Form1_Load(object sender, EventArgs e)
{

//加载数据库
OleDbConnection myConnection = new OleDbConnection(strConnect);
myConnection.Open();
string cmdpath = "select Path,number from Path";
//string cmdnum = "select number from number";
OleDbCommand com1 = new OleDbCommand(cmdpath, myConnection);
OleDbDataReader reader1 = com1.ExecuteReader();
try
{
for (int l = 0; l < 50; l++)
{
reader1.Read();
path[l] = reader1["path"].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//OleDbCommand com2 = new OleDbCommand(cmdnum, myConnection);
//OleDbDataReader reader2 = com2.ExecuteReader();
string[] a = new string[5];
for (int l = 0; l < 5; l++)
{
reader1.Read();
a[l] = reader1["number"].ToString();
}
i = int.Parse(a[0]);
//i1 = (int)a[1]; i2 = (int)a[2]; i3 = (int)a[3]; i4 = (int)a[4]; i5 = (int)a[5];
MessageBox.Show(i.ToString());

//加载Button
for (int m = 0; m < 5; m++)
{
for (int n = 0; n < 10; n++)
{
myButton[m * 10 + n] = new Button();
myButton[m * 10 + n].Left = 4 + 40 * n;
myButton[m * 10 + n].Top = 8;
myButton[m * 10 + n].Height = 32;
myButton[m * 10 + n].Width = 32;
//myButton[m * 10 + n].Visible = false;
myButton[m * 10 + n].ImageAlign = ContentAlignment.MiddleCenter;
myButton[m * 10 + n].Name = m.ToString() + n;
myButton[m * 10 + n].Text = (m * 10 + n).ToString();
tabControl1.TabPages[m].Controls.Add(myButton[m * 10 + n]);
myButton[m * 10 + n].MouseDown += new MouseEventHandler(this.myButtonDown);
if (path[m * 10 + n] != null)
{
myButton[m * 10 + n].BackgroundImage = Icon.ExtractAssociatedIcon(path[m * 10 + n]).ToBitmap();
myButton[m * 10 + n].Visible = true;
}

}
}
}


private void myButtonDown(object sender, MouseEventArgs e)
{
Button b = (Button)sender;
for (int m = 0; m < 5; m++)
{
for (int n = 0; n < 10; n++)
{
if (b.Name == m.ToString() + n)
{
try
{
FileInfo file = new FileInfo(path[m * 10 + n]);
Process p = new Process();
p.StartInfo.FileName = path[m * 10 + n];
p.StartInfo.WorkingDirectory = file.DirectoryName;
p.Start();
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message);
}
}
}

}

}
private void tabPage1_DragDrop(object sender, DragEventArgs e)
{
lnk[i1] = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(lnk[i1]);
path[i1] = link.TargetPath;

if (path[i1] != null)
{
UpdateData(path[i1], i1+1);


myButton[i1].BackgroundImage = Icon.ExtractAssociatedIcon(path[i1]).ToBitmap();
myButton[i1].Visible = true;
myButton[i1].MouseDown += new MouseEventHandler(this.myButtonDown);
i += 1;
i1 += 1;
MessageBox.Show(i1.ToString());
}
}

private void tabPage1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link; else e.Effect = DragDropEffects.None;
}

private void tabPage2_DragDrop(object sender, DragEventArgs e)
{
lnk[10 + i2] = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(lnk[10 + i2]);
path[10 + i2] = link.TargetPath;
if (path[10 + i2] != null)
{
UpdateData(path[10 + i2], 11 + i2);



myButton[10 + i2].BackgroundImage = Icon.ExtractAssociatedIcon(path[10 + i2]).ToBitmap();
myButton[10 + i2].Visible = true;
myButton[10 + i2].MouseDown += new MouseEventHandler(this.myButtonDown);
i += 1;
i2 += 1;
}
}

private void tabPage2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link; else e.Effect = DragDropEffects.None;
}

//同上
private void tabPage3_DragDrop(object sender, DragEventArgs e)
private void tabPage4_DragDrop(object sender, DragEventArgs e)
private void tabPage5_DragDrop(object sender, DragEventArgs e)


static void UpdateData(string path,int n)
{
string strConnect = "Provider=Microsoft.Jet.OleDb.4.0;data source=Desk.mdb";
OleDbConnection con = new OleDbConnection(strConnect);
con.Open();
string cmd = "update Path set Path= " + path + " where 编号 = " + n + "select * from Path";
OleDbCommand mycomd = new OleDbCommand(cmd, con);
//mycomd.CommandText = sqlstr;
//mycomd.Connection = con;
mycomd.ExecuteNonQuery();
//sqlstr = "Path[Path] = \'" + sqlstr + "\' where [编号] = \'" + n + "\'";
}


}
}
...全文
91 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
自由建客 2011-07-06
  • 打赏
  • 举报
回复
哇!这一百分散得……哈哈……
燃烧土豆 2011-07-06
  • 打赏
  • 举报
回复
实在太长了,只能说你自个打断定,只要肯调试没有解决不了的问题,程序员连基本的调试都不做就光问,那不是个合格的程序员
yanbing9113 2011-07-06
  • 打赏
  • 举报
回复
问题我已经自己解决了,还是要谢谢大家的关注!
yanbing9113 2011-07-06
  • 打赏
  • 举报
回复
已经实现了

string strConnect = "Provider=Microsoft.Jet.OleDb.4.0;data source=Desk.mdb";
OleDbConnection con = new OleDbConnection(strConnect);
con.Open();
string cmd = "update [Path] set Path= \'" + path[i1] + "\' where [编号] = " + (i1+1).ToString();
OleDbCommand mycomd = new OleDbCommand(cmd, con);
mycomd.ExecuteNonQuery();
肖恩 2011-07-06
  • 打赏
  • 举报
回复
试试
string cmd = "update Path set Path= " + path + " where 编号 = " + n + "select * from Path";
==》
string cmd =string.format("update Path set Path='{0}' where 编号 = {1} ;select * from Path",path,n);
yanbing9113 2011-07-06
  • 打赏
  • 举报
回复
不好意思,因为当时时间太紧。
那先解决一个问题吧,就是如何更新数据库,代码最后自定义了一个方法,不知道为啥实现不了
雪饮 2011-07-06
  • 打赏
  • 举报
回复
楼上+1
鸭梨山大帝 2011-07-06
  • 打赏
  • 举报
回复
1.下断点,查看哪个位置出错.
2.将详细错误信息贴出.

你直接这样贴一堆既没注释也没说明的代码,没人会花那么多时间去看的.
cjzzzx 2011-07-06
  • 打赏
  • 举报
回复
来观摩一下
isjoe 2011-07-06
  • 打赏
  • 举报
回复
难道是编译过不去???
xiongxyt2 2011-07-06
  • 打赏
  • 举报
回复
把错误信息贴出来
自由建客 2011-07-06
  • 打赏
  • 举报
回复
百分诱惑也是空的啊!

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧