已有56人关注
《C#从入门到精通》中企业人事管理系统的数据链接语句修改问题
发表在C#图书答疑 2011-06-28
是否精华
版块置顶:
我使用的是《C#从入门到精通》和《C#2005程序设计自学手册》这两本书,在使用《C#从入门到精通》这本书28章的“企业人事管理系统”时,修改了本机SQL的服务器地址后程序一直报错,我使用的链接语句为:
public static string M_str_sqlcon = "Data Source=COMPUTER\\MR;Database=db_PWMS;User id=sa;PWD=123456";
我的计算机名称就是COMPUTER,数据库实例名是MR,可以在SQL 2005中正常用sa账户登录访问数据库,但是在VS中就报找不到word错误
警告 1 下列引用的组件“Office ,VBIDE ,Word”有可用的已更新自定义包装。
错误 2 找不到类型或命名空间名称“Word”(是否缺少 using 指令或程序集引用?) C:\Users\Administrator\Desktop\PWMS\PWMS\PerForm\F_ManFile.cs 801 13 PWMS
错误 5 当前上下文中不存在名称“Word” C:\Users\Administrator\Desktop\PWMS\PWMS\PerForm\F_ManFile.cs 835 79 PWMS
错误 15 当前上下文中不存在名称“Word” C:\Users\Administrator\Desktop\PWMS\PWMS\PerForm\F_ManFile.cs 983 79 PWMS
重复的提示没有摘抄,我在使用《C#2005程序设计自学手册》这本书的时候是用如下的两句链接都没有问题
  conn = new SqlConnectio("server=computer\\mr;pwd=123456;uid=sa;database=db_showHouse");

  string M_str_sqlcon = "Data Source='computer\\mr';database='db_CRM';User id='sa';PWD='123456'";
分享到:
精彩评论 5
漫步沧海
学分:0 LV1
TA的每日心情
呵呵
2021-10-31 22:28:10
2011-06-28
沙发
能把问题说的在详细一些吗,word是在哪里定义的
学分: LV1
TA的每日心情
开心
2021-09-12 16:35:53
2011-06-28
板凳
我使用的是《C#从入门到精通》本书所赠送光盘里28章的那个系统,学习到这里了,想在电脑上调试出来看看。
系统中的说明是“[font color=#0000FF]更改连接SQL Server 2005数据库服务器的名称
(1)打开源程序路径下TM\07\PWMS\PWMS.sln,进入到Visual Studio 2005开发环境中。
(2)在解决方案资源管理器中打开DataClass文件夹中的MyMeans.cs类文件,将“全局变量”方法中的连接字符串的Data Source属性设置为本机SQL Server 2005服务器名称,然后单击【保存】按钮,保存所做的更改。
(3)重新生成后,即可运行使用本程序。”[/font]
我是照着上面做的,但是修改之后就报错,我跟换了上面所说的两种连接语句,都不可以
请给予回复,谢谢
小科_mrkj
学分:43 LV2
2011-06-28
地板
读者朋友:
    您好,这个问题不是数据库连接的问题,你需要在“添加引用”中添加Word 9.0引用。
学分: LV1
TA的每日心情
开心
2021-09-12 16:35:53
2011-06-28
4L
我的是Microsoft Word 11.0 Object Library的这个版本。
能直接引用吗?
还有程序里原来就有的word引用,VBIDE引用还要删去吗?
小科_mrkj
学分:43 LV2
2011-07-01
5L
读者朋友:
您好,该程序需要添加Word 9.0引用,而如果你引用的是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 下一页尾页 5 条记录 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经营性网站备案信息 营业执照