本文介绍了与sql server 2008在c#windows窗体中具有Ms访问权限的vb6 adodb的recordset.find相当于什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我的名字是vishal我正在翻译/解释一个vb6代码adodb,其中Ms访问c#code with sql server 2008.

下面给出的是vb6代码:

Hi my name is vishal i am translating/interpreting a vb6 code adodb with Ms access into c# code with sql server 2008.
Given below is vb6 code:

Dim sItemData As String
Dim strData As String
Dim strOutData As String
Dim strConnect As String
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Prices.mdb;Persist Security Info=False"
    Dim strPath As String
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Persist Security Info=False;Data Source=" & strPath & _
      "; Mode=Read|Write"
    Dim rs As New ADODB.Recordset
strData = "Item = '" & sItemData & "'"
   rs.Open "select * from prices", strConnect, adOpenKeyset, adLockOptimistic
    rs.Find strData
    strOutData = rs.Fields("Price")



以下是我的c#代码翻译/解释上述vb6代码:


Given below is my c# code translation/interpretation of above vb6 code:

string sItemData="";
        string strOutData;
string strData;
            strData = "Item = '" + sItemData + "'";
 SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Winsock;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string root = ("Select * from Prices");
            SqlCommand cmd = new SqlCommand(root);
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                
                strOutData = dr[1].ToString();
            }



一切顺利,除非我无法翻译/解释给定的vb6代码行:


every thing goes okay except i am unable to translate/interpret given vb6 code line:

rs.Find strData



使用sql server 2008进入c#代码。

任何人都可以帮助我!在使用sql server将vb6代码转换为c#代码时,我正在朝着正确的方向前进吗?用cql server 2008告诉我c#中的rs.Find相当于什么?告诉我必须在sql server 2008的c#代码中做什么修改。非常感谢解决这个问题的任何帮助/指导!任何人都可以帮助我!


into c# code with sql server 2008.
Can anyone help me please! Am going in right direction in translating above vb6 code into c# code with sql server? Tell me what is equivalent of rs.Find in c# with sql server 2008? Tell me what modifications must i do in my c# code with sql server 2008. Any help/guidance in solving of this problem would be greatly appreciated! Can anyone help me !

推荐答案

"Select * from Prices where item = @itemdata"



并将参数添加到 cmd



是的,你正朝着正确的方向远离VB6! !如果它符合您的需求,C#是一个不错的选择。你没有同时离开Access,但它也是一个好动作


and add a parameter to cmd

And yes you are going in the right direction moving away from VB6!! C# is a good choice if it fits your needs. You didn't have to move away from Access at the same time, but it's is also a Good Move


while (dr.Read())
            {
                if (dr[1].ToString()==strData)
                {
                    strOutData = dr[1].ToString();
                {
            }


这篇关于与sql server 2008在c#windows窗体中具有Ms访问权限的vb6 adodb的recordset.find相当于什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 16:31