当前位置:编程学习 > C#/ASP.NET >>

c#怎样数据库中某一条数据在数据库中的位置传递给CurrencyManager.Position

c#怎样查询数据库中某一条数据,将这条数据在数据库中的位置传递给CurrencyManager.Position
在一个学生学籍管理系统中的学籍查询界面,我想增加一条按学号进行查询,并将查询结果显示在学生学籍查询界面。
,我将代码和界面贴在下面,我是个小菜鸟,请各位高手看看。我的想法是查询出相应学号的数据在数据库中的位置,将其值赋给cm.Position ,各位高手看看该怎么弄啊?我用的是ACCESS数据库

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data ;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 学生学籍管理系统
{
    public partial class ApdateStuInfo: Form
    {
        CurrencyManager cm;
        public ApdateStuInfo()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void DealStuInfo_Load(object sender, EventArgs e)
        {
            string connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=xsxjdb.mdb";
            string sqlstring = "select * from StudentInfo";
            OleDbConnection oldconn = new OleDbConnection(connstring);
            oldconn.Open();
            OleDbDataAdapter oda = new OleDbDataAdapter(sqlstring, connstring);
            DataSet ds = new DataSet();
            oda.Fill(ds, "StudentInfo");
            textBox1.DataBindings.Add("Text", ds, "StudentInfo.Num");
            textBox2.DataBindings.Add("Text", ds, "StudentInfo.Name");
            textBox6.DataBindings.Add("Text", ds, "StudentInfo.Sex");
            textBox3.DataBindings.Add("Text", ds, "StudentInfo.Date");
            textBox4.DataBindings.Add("Text", ds, "StudentInfo.Place");
            textBox7.DataBindings.Add("Text", ds, "StudentInfo.Politics");
            textBox5.DataBindings.Add("Text", ds, "StudentInfo.CardNum");
            textBox8.DataBindings.Add("Text", ds, "StudentInfo.SpeNum");
            cm = (CurrencyManager)this.BindingContext[ds, "StudentInfo"];
            cm.Position = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (cm.Position == 0)
            {
                MessageBox.Show("已经是第一条记录了", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
                cm.Position = 0;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            cm.Position--;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (cm.Position == cm.Count - 1)
            {
                MessageBox.Show("已经是最后一条记录", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
                cm.Position++;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            cm.Position = cm.Count - 1;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
--------------------编程问答-------------------- DataRow[] drs = dt.Select("StudentInfo.Num = ‘’"); --------------------编程问答-------------------- 能给仔细说说吗,最好能给出段完整代码啊
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,