本文介绍了无法从本地数据库中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在学习C# 而我正在尝试创建简单的词典,将英语单词翻译成我的母语。 我无法理解我在哪里制作错误,我想从本地数据库中检索数据,当用户按下按钮button1 现在它显示这样的消息:你的应用程序中发生了未处理的异常... 以下是我的程序代码: private void button1_Click( object sender,EventArgs e) { 尝试 { SqlCeConnection con = new SqlCeConnection( c:\\users \\\\\\\\\\\\\\\\\\\\\工作室2012 \\\Projects\\Sozluk\\Sozluk\\dictionary.sdf); SqlCeCommand com = new SqlCeCommand( 选择来自sozler的soz,terjime,mysal soz =' + soz1.Text + ',con); con.Open(); SqlCeDataReader reader = com.ExecuteReader(); if (reader.Read()) { soz1.Text = reader.GetString( 0 ); terjime1.Text = reader.GetString( 1 ); mysal1.Text = reader.GetString( 2 ); } else { MessageBox.Show( 无效的单词, 字典,MessageBoxButtons.OK,MessageBoxIcon.Error); } } catch (SqlCeException) { MessageBox .Show( 错误); // 这将是一个改进,而不仅仅是'错误'这个词 } } 解决方案 以下链接解释了如何部署SQLServer Compact http://msdn.microsoft.com/en-us/library/aa983326(v = vs.90).aspx [ ^ ] 这个是解释如何在部署中添加数据库 http://msdn.microsoft.com/en-us/lib rary / aa983340(v = vs.90).aspx [ ^ ] 希望它解决问题 I am learning C#and I am trying to create simple dictionary which will translate words from english to my native language.I can't understand where i made mistake, i want to retrieve data from local database when user will press button "button1"now it shows such message: Unhandled exception has occured in your application...The following are my code of program: private void button1_Click(object sender, EventArgs e) { try { SqlCeConnection con = new SqlCeConnection("c:\\users\\rustam\\documents\\visual studio 2012\\Projects\\Sozluk\\Sozluk\\dictionary.sdf"); SqlCeCommand com = new SqlCeCommand("Select soz, terjime, mysal from sozler where soz='" + soz1.Text + "'", con); con.Open(); SqlCeDataReader reader = com.ExecuteReader(); if (reader.Read()) { soz1.Text = reader.GetString(0); terjime1.Text = reader.GetString(1); mysal1.Text = reader.GetString(2); } else { MessageBox.Show("Invalid Word", "Dictionary", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (SqlCeException) { MessageBox.Show("Error"); // Would be an improvement than just the word 'Error' } } 解决方案 这篇关于无法从本地数据库中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!