已有56人关注
c#从入门到精通,企业人事管理系统,无头绪的错误。
发表在C#图书答疑 2009-04-21
是否精华
版块置顶:
小科老师您好:

问题一:
c#从入门到精通这本书最后一章的企业人事管理系统,感觉真是全书的精华,从分析到实施后实现和打包,整个软件项目开发的主要过程都包括,兴奋的想运行下软件是怎样的,却不能随心所愿,发现有两个问题,向您请教。

一,在不附加数据前提下,用vs2005打开系统,然后运行,出现85个类似错误,提示如下:
说明 “Word.Tables”并不包含“Item”的定义 
文件 D:\c#从入门到精通光盘\28\PWMS\PWMS\PerForm\F_ManFile.cs 
行 846 
列 32 
项目 PWMS

二,打开Microsoft SQL Server Management Studio,2005的数据库系统,附加数据库db_PWMS.mdf时发生错,提示如下:
执行 Transact-SQL 语句或批处理时发生了异常。 (Microsoft.SqlServer.ConnectionInfo)。
------------------------------
未能在 sysindexes 中找到数据库 ID 12 中对象 ID 1 的索引 ID 1 对应的行。请对 sysindexes 运行 DBCC CHECKTABLE。
Could not find row in sysindexes for database ID 12, object ID 1, index ID 1. Run DBCC CHECKTABLE on sysindexes.
未能打开新数据库 'db_PWMS'。CREATE DATABASE 将终止。 (Microsoft SQL Server,错误: 602)

有关帮助信息,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=602&LinkId=20476

另外用sql server2000数据库管理系统附加时也发生同样的错误。


问题二:
Microsoft SQL Server Management Studio 9.00.1399.00
Microsoft Analysis Services 客户端工具 2005.090.1399.00
Microsoft 数据访问组件 (MDAC) 2000.085.1117.00 (xpsp_sp2_rtm.040803-2158)
Microsoft MSXML 2.6 3.0 4.0 5.0 6.0 
Microsoft Internet Explorer 6.0.2900.2180
Microsoft .NET Framework 2.0.50727.832
操作系统 5.1.2600

肯定是9.0的,我同时装了sql server2005,和sql server2000,打开2个版本的数据库管理器都不能附加成功,但附加书中其他数据库都能成功。


问题三:
我装的是office2003
在COM选项卡里添加word11.0组件报错,好像已存在了,错误提示:

未能添加对“Microsoft Word 11.0 Object Library”的引用。已存在对此类型库的引用。添加此类型库之前必须移除引用“Word”。

另外想添加word9.0试试,但没有找到该组件。


问题四:
文件 F_ManFile.cs 885 行 36列 对该代码
wordDoc.Tables.Item(1).Cell(1, 5).Range.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);

wordDoc 右键‘转到定义(G)’

转到代码 Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

然后对Word 右键‘转到定义(G)’ 出现错误,如下:
无法导航到“Word”

不知道这个对错误 ““Word.Tables”并不包含“Item”的定义 “有没有帮助。


问题五:
public SqlConnection (
string connectionString
)
参数 connetionString 初始化写法是怎样的,怎我见的形式那么多呢,麻烦你解释下
1.msdn版本 
string connection ="Data Source=(local);Initial Catalog=AdventureWorks;"
+ "Integrated Security=SSPI;";


2.c#从入门到精通15章写法
string connection =“server=.; database=db_15; uid=sa; pwd=”;

3.c#从入门到精通最后章企业人事管理系统的写法

string M_str_sqlcon = @"Data Source=MRDEL\SQLEXPRESS;Initial Catalog=db_PWMS;Integrated Security=True";

string M_str_sqlcon = "Data Source=mrwxk\\wxk;Database=db_PWMS;User id=sa;PWD=";


急需要全程研究这个项目,和自己动手做遍,遇到这两个问题解决不了变的无从下手,恳求小科老师百忙中多费点时间,帮我解决下究竟是哪里出现问题了,先谢谢了!
分享到:
精彩评论 3
小科_mrkj
学分:43 LV2
2009-04-21
沙发
读者朋友:
    您好,问题回复如下:
    (1)出现这种问题是由于没有添加Word引用造成的,由于版权问题,我们的光盘中没有附带Word组件,您需要打开程序,然后选中项目,单击右键选择“添加引用”,然后在添加引用中切换到COM选项卡,添加Word 9.0引用,如果装的是Office 2003,可以添加Word 11.0引用,不过需要将代码中用到Word对象的地方都是用全称进行声明,比如Microsoft.Office.Word。
    (2)光盘中的数据库应该可以正常附加,因为如果读者用的是2005数据库,他们的都是可以附加的,只有跟我们要转换成2000后的数据库的(因为他们的机器上没有装2005),你如果需要,可以给我们留一个邮箱地址,我们给你发一个,你再看一下。
    (3)添加word组件报错,你就在解决方案资源管理器中把原来的word引用先删掉,然后再填;另外,没有找到word9.0是因为你的机器上装的是word 2003,如果装的是word 2000,就可以找到word9.0了。
    (4)这个没有关系,“转到定义”是针对于.net中的类库或者自定义的方法、变量的。
    (5)第一种形式是使用Windows身份验证登录的数据库;第二种形式是连接本地的SQL 2000服务器,其中的server也可以换成Data Source;第三种形式是连接本地的SQL 2005数据库,它跟第二种形式其实是一样的,只不过服务器名改成了SQL 2005的服务器名,另外,第三种中的第一个是直接在字符串最前面加了@转义符,这样的话,后面用到\\的直接写\就行了,而且它是使用Windows身份验证登录SQL 2005服务器,第二个由于前面没有加@转义符,所以用到\时就得写成\\,其中的一个\表示转义。
alimjan410
学分:0 LV1
2009-05-11
板凳
小科老师你好:

我也弄不好第三个问题怎么办呀帮帮我。。以经引用了word不过还是处错误14个错误。
你说的  声明是 什么意思。。。把word替换microsoft.office.world吗???还是怎么样
我把有些信息发到您的邮箱里帮忙我好吗?
我的 电子邮件是:alimjan410@126.com
QQ:409017801
希望您肯帮我谢谢?[img src=null/img]
小科_mrkj
学分:43 LV2
2009-05-13
地板
读者朋友:
    您好,如果引用的是Word 11.0,请将“人事档案管理”窗体中的“Word文档”按钮的Click事件下的代码替换为如下代码。

object Nothing = System.Reflection.Missing.Value;
object missing = System.Reflection.Missing.Value;
//创建Word文档
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordApp.Visible = true;
//设置文档宽度
wordApp.Selection.PageSetup.LeftMargin = wordApp.CentimetersToPoints(float.Parse("2"));
wordApp.ActiveWindow.ActivePane.HorizontalPercentScrolled = 11;
wordApp.Selection.PageSetup.RightMargin = wordApp.CentimetersToPoints(float.Parse("2"));
Object start = Type.Missing;
Object end = Type.Missing;
PictureBox pp = new PictureBox();//新建一个PictureBox控件
int p1 = 0;
for (int i = 0; i < MyDS_Grid.Tables[0].Rows.Count; i++)
{
    try
    {
        byte[] pic = (byte[])(MyDS_Grid.Tables[0].Rows[i][23]);//将数据库中的图片转换成二进制流
        MemoryStream ms = new MemoryStream(pic);//将字节数组存入到二进制流中
        pp.Image = Image.FromStream(ms);//二进制流Image控件中显示
        pp.Image.Save(@"C:\22.bmp");//将图片存入到指定的路径
    }
    catch
    {
        p1 = 1;
    }
    object rng = Type.Missing;
    string strInfo = "职工基本信息表" + "(" + MyDS_Grid.Tables[0].Rows[i][1].ToString() + ")";
    start = 0;
    end = 0;
    wordDoc.Range(ref start, ref end).InsertBefore(strInfo);//插入文本
    wordDoc.Range(ref start, ref end).Font.Name = "Verdana";//设置字体
    wordDoc.Range(ref start, ref end).Font.Size = 20;//设置字体大小
    wordDoc.Range(ref start, ref end).ParagraphFormat.Alignment =     Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//设置字体居中
    start = strInfo.Length;
    end = strInfo.Length;
    wordDoc.Range(ref start, ref end).InsertParagraphAfter();//插入回车
    object missingValue = Type.Missing;
    //如果location超过已有字符的长度将会出错。一定要比"明细表"串多一个字符
    object location = strInfo.Length;
    Microsoft.Office.Interop.Word.Range rng2 = wordDoc.Range(ref location, ref location);
    Microsoft.Office.Interop.Word.Table tab = wordDoc.Tables.Add(rng2, 14, 6, ref missingValue, ref missingValue);
    tab.Rows.HeightRule = Microsoft.Office.Interop.Word.WdRowHeightRule.wdRowHeightAtLeast;
    tab.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));
    tab.Range.Font.Size = 10;
    tab.Range.Font.Name = "宋体";
    //设置表格样式
    tab.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
    tab.Borders.InsideLineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;
    tab.Borders.InsideColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
    wordApp.Selection.ParagraphFormat.Alignment =     Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐
    tab.Cell(1, 5).Merge(tab.Cell(5, 6));//第5行显示
    tab.Cell(6, 5).Merge(tab.Cell(6, 6));//第6行显示
    tab.Cell(9, 4).Merge(tab.Cell(9, 6));//第9行显示
    tab.Cell(12, 2).Merge(tab.Cell(12, 6));//第12行显示
    tab.Cell(13, 2).Merge(tab.Cell(13, 6));//第13行显示
    tab.Cell(14, 2).Merge(tab.Cell(14, 6));//第14行显示
    //第1行赋值
    tab.Cell(1, 1).Range.Text = "职工编号:";
    tab.Cell(1, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][0].ToString();
    tab.Cell(1, 3).Range.Text = "职工姓名:";
    tab.Cell(1, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][1].ToString();
    //插入图片
    if (p1 == 0)
    {
        string FileName = @"C:\22.bmp";//图片所在路径
        object LinkToFile = false;
        object SaveWithDocument = true;
        object Anchor = tab.Cell(1, 5).Range;//指定图片插入的区域
        //将图片插入到单元格中
        tab.Cell(1, 5).Range.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
     }
     p1 = 0;
     //第2行赋值
     tab.Cell(2, 1).Range.Text = "民族类别:";
     tab.Cell(2, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][2].ToString();
     tab.Cell(2, 3).Range.Text = "出生日期:";
     try
     {
         tab.Cell(2, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][3]).ToShortDateString());
     }
     catch { tab.Cell(2, 4).Range.Text = ""; }
     //第3行赋值
     tab.Cell(3, 1).Range.Text = "年龄:";
     tab.Cell(3, 2).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][4]);
     tab.Cell(3, 3).Range.Text = "文化程度:";
     tab.Cell(3, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][5].ToString();
     //第4行赋值
     tab.Cell(4, 1).Range.Text = "婚姻:";
     tab.Cell(4, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][6].ToString();
     tab.Cell(4, 3).Range.Text = "性别:";
     tab.Cell(4, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][7].ToString();
     //第5行赋值
     tab.Cell(5, 1).Range.Text = "政治面貌:";
     tab.Cell(5, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][8].ToString();
     tab.Cell(5, 3).Range.Text = "单位工作时间:";
     try
     {
         tab.Cell(5, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[0][10]).ToShortDateString());
     }
     catch { tab.Cell(5, 4).Range.Text = ""; }
     //第6行赋值
     tab.Cell(6, 1).Range.Text = "籍贯:";
     tab.Cell(6, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][24].ToString();
     tab.Cell(6, 3).Range.Text = MyDS_Grid.Tables[0].Rows[i][25].ToString();
     tab.Cell(6, 4).Range.Text = "身份证:";
     tab.Cell(6, 5).Range.Text = MyDS_Grid.Tables[0].Rows[i][9].ToString();
     //第7行赋值
     tab.Cell(7, 1).Range.Text = "工龄:";
     tab.Cell(7, 2).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][11]);
     tab.Cell(7, 3).Range.Text = "职工类别:";
     tab.Cell(7, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][12].ToString();
     tab.Cell(7, 5).Range.Text = "职务类别:";
     tab.Cell(7, 6).Range.Text = MyDS_Grid.Tables[0].Rows[i][13].ToString();
     //第8行赋值
     tab.Cell(8, 1).Range.Text = "工资类别:";
     tab.Cell(8, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][14].ToString();
     tab.Cell(8, 3).Range.Text = "部门类别:";
     tab.Cell(8, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][15].ToString();
     tab.Cell(8, 5).Range.Text = "职称类别:";
     tab.Cell(8, 6).Range.Text = MyDS_Grid.Tables[0].Rows[i][16].ToString();
     //第9行赋值
     tab.Cell(9, 1).Range.Text = "月工资:";
     tab.Cell(9, 2).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][26]);
     tab.Cell(9, 3).Range.Text = "银行账号:";
     tab.Cell(9, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][27].ToString();
     //第10行赋值
     tab.Cell(10, 1).Range.Text = "合同起始日期:";
     try
     {
         tab.Cell(10, 2).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][28]).ToShortDateString());
     }
     catch { tab.Cell(10, 2).Range.Text = ""; }
     tab.Cell(10, 3).Range.Text = "合同结束日期:";
     try
     {
         tab.Cell(10, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][29]).ToShortDateString());
     }
     catch { tab.Cell(10, 4).Range.Text = ""; }
     tab.Cell(10, 5).Range.Text = "合同年限:";
     tab.Cell(10, 6).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][30]);
     //第11行赋值
     tab.Cell(11, 1).Range.Text = "电话:";
     tab.Cell(11, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][17].ToString();
     tab.Cell(11, 3).Range.Text = "手机:";
     tab.Cell(11, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][18].ToString();
     tab.Cell(11, 5).Range.Text = "毕业时间:";
     try
     {
         tab.Cell(11, 6).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][21]).ToShortDateString());
     }
     catch { tab.Cell(11, 6).Range.Text = ""; }
     //第12行赋值
     tab.Cell(12, 1).Range.Text = "毕业学校:";
     tab.Cell(12, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][19].ToString();
     //第13行赋值
     tab.Cell(13, 1).Range.Text = "主修专业:";
     tab.Cell(13, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][20].ToString();
     //第14行赋值
     tab.Cell(14, 1).Range.Text = "家庭地址:";
     tab.Cell(14, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][22].ToString();
     wordDoc.Range(ref start, ref end).InsertParagraphAfter();//插入回车
     wordDoc.Range(ref start, ref end).ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//设置字体居中
  
首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照