编程遇到了很多难题,不知道该怎么修改,哪位高手帮忙看看哪里出现了问题。部分代码因字数问题省略了
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 + "\'";
        }       
           }
}

解决方案 »

  1.   

    试试
    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);
      

  2.   

    已经实现了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();