[英]Retrieving information stored in a SQL Server CE database in Visual Studio 2010
I asked a question [HERE] and we got all the information stored in the database SQL Server CE database. 我问了一个问题[HERE] ,我们将所有信息存储在SQL Server CE数据库中。
The question remains now how to get the information stored back into variables. 现在的问题仍然是如何将信息存储回到变量中。
This line of code: 这行代码:
myReader.SqlCeReader();
will not compile, I am asked if I have missed a compiler reference what ever that is. 不会编译,我被问到是否错过了编译器参考。
The information is stored as strings with an Integer “ID” primary key. 信息以带有整数“ ID”主键的字符串存储。
The information will be used to create shortcuts on a disk suitable for launching, images in paint, executable programs and so on. 该信息将用于在适合启动的磁盘上创建快捷方式,绘画中的图像,可执行程序等。 They should not be more than strings which is why I find it hard to do, it should be simple.
它们不应该只是字符串,这就是为什么我觉得很难做到的原因,它应该很简单。
A sample record 样本记录
id=int NstacksName=String NstacksPath=String.
I think I have it all wrong and am surprised it even compiles this far. 我认为我全都错了,很惊讶它到目前为止还可以编译。
private void label2_Click(object sender, EventArgs e)
{
string DirName;
SqlCeConnection conn = new SqlCeConnection("Data Source=C:\\Users\\username\\Documents\\Visual Studio 2010\\Projects\\NStacks1\\NStacks1\\Database1.sdf");
String name;
try
{
conn.Open();
SqlCeCommand Command = new SqlCeCommand("SELECT * FROM NStacks1 WHERE ID = 1", conn);
DataTable Data = new DataTable();
SqlCeDataAdapter adapter = new SqlCeDataAdapter(Command);
SqlCeDataReader myReader;
try
{
myReader.SqlCeReader();
DirName = Data.ToString();
con.Close();
name = DirName;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
}
private void button4_Click(object sender, EventArgs e)
{
string SName, NStackPath;
string source=("Data Source=C:\\Users\\username\\Documents\\Visual Studio 2010\\Projects\\NStacks1\\NStacks1\\Database1.sdf");
SqlCeConnection Con = new SqlCeConnection(source);
try{
Con.Open();
string Query= "SELECT * FROM Nstacks1 WHERE ID=1";
SqlCeCommand command = new SqlCeCommand(Query , Con);
SqlCeDataReader dr = command.ExecuteReader();
if (dr.Read())
{
textBox1.Text=(dr["NStacksName"].ToString());
label2.Text = (dr["NStacksItem"].ToString());
}
Con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.