请高人帮忙把c#代码转化成vb代码,急用,谢谢!
private void lbxStage_SelectedIndexChanged(object sender, System.EventArgs e)
{
lbxRhythm.Items.Clear ();
lbxMusic.Items.Clear ();// int speed =0;
m_CurStageNo = lbxStage.SelectedIndex + 1;// string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection; myCommand.CommandText ="SelectRhythmNoByStageNo";
myCommand.CommandType  = CommandType.StoredProcedure ; SqlParameter myParm = myCommand.Parameters.Add("@StageNo", SqlDbType.Int , 18);
myCommand.Parameters["@StageNo"].Value = m_CurStageNo ;
myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(myReader.Read()) 
{
lbxRhythm.Items.Add(myReader["RhythmNo"]);
m_CurNoteTM = int.Parse( myReader["NoteTM"].ToString()) ;
}
myReader.Close(); m_isSelectStage= true;
switch(m_CurNoteTM)       
{         
case 1000:   
lbxSpeed.SelectedIndex  = 0;
break;                  
case 800:   
lbxSpeed.SelectedIndex  = 1;
break;                  
case 600:            
lbxSpeed.SelectedIndex  = 2;
break;
case 480:            
lbxSpeed.SelectedIndex  = 3;
break;
case 400:            
lbxSpeed.SelectedIndex  = 4;
break;
default:  
// lbxSpeed.SelectedIndex  = 0;
break;      
} m_isSelectStage = false;
m_isBtnAddClicked=false;

} private void lbxRhythm_SelectedIndexChanged(object sender, System.EventArgs e)
{
lbxMusic.Items.Clear (); m_CurRhythmNo = lbxRhythm.SelectedIndex + 1;
// string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection; myCommand.CommandText ="SelectMusicByStageNoRythmNo";
myCommand.CommandType  = CommandType.StoredProcedure ; SqlParameter myParm = myCommand.Parameters.Add("@StageNo", SqlDbType.Int , 18);
myCommand.Parameters["@StageNo"].Value = m_CurStageNo; myParm = myCommand.Parameters.Add("@RhythmNo", SqlDbType.Int , 18);
myCommand.Parameters["@RhythmNo"].Value = m_CurRhythmNo; myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(myReader.Read()) 
{
lbxMusic.Items.Add(myReader["DelayTM"]);
}
myReader.Close();


} private void lbxSpeed_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (m_isSelectStage) return;
// int speed =400; switch(lbxSpeed.SelectedIndex)       
{         
case 0:   
m_CurNoteTM = 1000;
m_CurDelayTM = m_CurNoteNM * m_CurNoteTM;
break;                  
case 1:   
m_CurNoteTM = 800;
m_CurDelayTM = m_CurNoteNM * m_CurNoteTM;
break;                  
case 2:            
m_CurNoteTM = 600;
m_CurDelayTM = m_CurNoteNM * m_CurNoteTM;
break;
case 3:            
m_CurNoteTM = 480;
m_CurDelayTM = m_CurNoteNM * m_CurNoteTM;
break;
case 4:            
m_CurNoteTM = 400;
m_CurDelayTM = m_CurNoteNM * m_CurNoteTM;
break;
default:  
break;      
}
int cmdresults = 0;// string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection; myCommand.CommandText = "UpdateDataBySpeed";
myCommand.CommandType = CommandType.StoredProcedure; SqlParameter myParm = myCommand.Parameters.Add("@NoteTM", SqlDbType.Int , 18);
myCommand.Parameters["@NoteTM"].Value = m_CurNoteTM; myConnection.Open(); try
{
cmdresults = myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("Failed to execute command" + ex.ToString() );
}
myConnection.Close();
// MessageBox.Show("Number of records updated = " + cmdresults.ToString());
} private void lbxMusic_SelectedIndexChanged(object sender, System.EventArgs e)
{

} private void btnDelete_Click(object sender, System.EventArgs e)
{ int cmdresults = 0;// string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection; myCommand.CommandText = "DeleteMusicByStageNoRhythmNo";
myCommand.CommandType = CommandType.StoredProcedure; SqlParameter myParm = myCommand.Parameters.Add("@Original_StageNo", SqlDbType.Int , 18);
myCommand.Parameters["@Original_StageNo"].Value = m_CurStageNo; myParm = myCommand.Parameters.Add("@Original_RhythmNo", SqlDbType.Int , 18);
myCommand.Parameters["@Original_RhythmNo"].Value = m_CurRhythmNo;
myConnection.Open(); try
{
cmdresults = myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("Failed to execute command" +ex.ToString ());
}
myConnection.Close(); m_isBtnAddClicked= false;
int temp = (int)m_CurStageNo; if (temp+1 > 20)
{
lbxStage.SelectedIndex = 0;
}
else{
lbxStage.SelectedIndex = temp;
}
lbxStage.SelectedIndex = temp-1;// MessageBox.Show("Number of records deleted = " + cmdresults.ToString());

}

解决方案 »

  1.   


    'Error: Converting Methods, Functions and Constructors 
    'Error: Converting If-Else-End If Blocks private void lbxStage_SelectedIndexChanged(Object sender, System.EventArgs e)
    {
    lbxRhythm.Items.Clear ()
    lbxMusic.Items.Clear ()
     
    ' int speed =0;
    m_CurStageNo = lbxStage.SelectedIndex + 1
     
    ' string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
    Dim myConnection As SqlConnection =  New SqlConnection(myConnectionString) 
    Dim myCommand As SqlCommand =  New SqlCommand() 
    myCommand.Connection = myConnection
     
    myCommand.CommandText ="SelectRhythmNoByStageNo"
    myCommand.CommandType = CommandType.StoredProcedure 
     
    Dim myParm As SqlParameter =  myCommand.Parameters.Add("@StageNo",SqlDbType.Int,18) 
    myCommand.Parameters("@StageNo").Value = m_CurStageNo 
    myConnection.Open()
     
    Dim myReader As SqlDataReader =  myCommand.ExecuteReader(CommandBehavior.CloseConnection) 
    While myReader.Read()
    lbxRhythm.Items.Add(myReader("RhythmNo"))
    m_CurNoteTM = Integer.Parse(myReader("NoteTM").ToString()) 
    End While
    myReader.Close()
     
    m_isSelectStage= True
    Select Case m_CurNoteTM
    Case 1000
    lbxSpeed.SelectedIndex = 0
    Exit While   
    Case 800
    lbxSpeed.SelectedIndex = 1
    Exit While   
    Case 600
    lbxSpeed.SelectedIndex = 2
    Exit While
    Case 480
    lbxSpeed.SelectedIndex = 3
    Exit While
    Case 400
    lbxSpeed.SelectedIndex = 4
    Exit While
    Case Else
    ' lbxSpeed.SelectedIndex = 0;
    Exit While
    End Select
     
    m_isSelectStage = False
    m_isBtnAddClicked=False
     
    }
     
    private void lbxRhythm_SelectedIndexChanged(Object sender, System.EventArgs e)
    {
    lbxMusic.Items.Clear ()
     
    m_CurRhythmNo = lbxRhythm.SelectedIndex + 1
     
     
    ' string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
    Dim myConnection As SqlConnection =  New SqlConnection(myConnectionString) 
    Dim myCommand As SqlCommand =  New SqlCommand() 
    myCommand.Connection = myConnection
     
    myCommand.CommandText ="SelectMusicByStageNoRythmNo"
    myCommand.CommandType = CommandType.StoredProcedure 
     
    Dim myParm As SqlParameter =  myCommand.Parameters.Add("@StageNo",SqlDbType.Int,18) 
    myCommand.Parameters("@StageNo").Value = m_CurStageNo
     
    myParm = myCommand.Parameters.Add("@RhythmNo", SqlDbType.Int , 18)
    myCommand.Parameters("@RhythmNo").Value = m_CurRhythmNo
     
    myConnection.Open()
     
    Dim myReader As SqlDataReader =  myCommand.ExecuteReader(CommandBehavior.CloseConnection) 
    While myReader.Read()
    lbxMusic.Items.Add(myReader("DelayTM"))
    End While
    myReader.Close()
     
     
    }
     
    private void lbxSpeed_SelectedIndexChanged(Object sender, System.EventArgs e)

    Dim Return As if(m_isSelectStage)
    ' int speed =400;
     
    Select Case lbxSpeed.SelectedIndex
    Case 0
    m_CurNoteTM = 1000
    m_CurDelayTM = m_CurNoteNM * m_CurNoteTM
    Exit While   
    Case 1
    m_CurNoteTM = 800
    m_CurDelayTM = m_CurNoteNM * m_CurNoteTM
    Exit While   
    Case 2
    m_CurNoteTM = 600
    m_CurDelayTM = m_CurNoteNM * m_CurNoteTM
    Exit While
    Case 3
    m_CurNoteTM = 480
    m_CurDelayTM = m_CurNoteNM * m_CurNoteTM
    Exit While
    Case 4
    m_CurNoteTM = 400
    m_CurDelayTM = m_CurNoteNM * m_CurNoteTM
    Exit While
    Case Else
    Exit While
    End Select
     
     
    Dim cmdresults As Integer =  0 
     
    ' string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
    Dim myConnection As SqlConnection =  New SqlConnection(myConnectionString) 
    Dim myCommand As SqlCommand =  New SqlCommand() 
    myCommand.Connection = myConnection
     
    myCommand.CommandText = "UpdateDataBySpeed"
    myCommand.CommandType = CommandType.StoredProcedure
     
    Dim myParm As SqlParameter =  myCommand.Parameters.Add("@NoteTM",SqlDbType.Int,18) 
    myCommand.Parameters("@NoteTM").Value = m_CurNoteTM
     
    myConnection.Open()
     
    Try
    cmdresults = myCommand.ExecuteNonQuery()
    Catch ex As Exception
    MessageBox.Show("Failed to execute command" + ex.ToString())
    End Try
    myConnection.Close()
    ' MessageBox.Show("Number of records updated = " + cmdresults.ToString());
    }
     
    private void lbxMusic_SelectedIndexChanged(Object sender, System.EventArgs e)
    {
     
    }
     
    private void btnDelete_Click(Object sender, System.EventArgs e)
    {
     
    Dim cmdresults As Integer =  0 
     
    ' string myConnectionString="server=LINBELL;UID=mgame;PWD=mgame;database=mgame";
    Dim myConnection As SqlConnection =  New SqlConnection(myConnectionString) 
    Dim myCommand As SqlCommand =  New SqlCommand() 
    myCommand.Connection = myConnection
     
    myCommand.CommandText = "DeleteMusicByStageNoRhythmNo"
    myCommand.CommandType = CommandType.StoredProcedure
     
    Dim myParm As SqlParameter =  myCommand.Parameters.Add("@Original_StageNo",SqlDbType.Int,18) 
    myCommand.Parameters("@Original_StageNo").Value = m_CurStageNo
     
    myParm = myCommand.Parameters.Add("@Original_RhythmNo", SqlDbType.Int , 18)
    myCommand.Parameters("@Original_RhythmNo").Value = m_CurRhythmNo
     
     
    myConnection.Open()
     
    Try
    cmdresults = myCommand.ExecuteNonQuery()
    Catch ex As Exception
    MessageBox.Show("Failed to execute command" +ex.ToString())
    End Try
    myConnection.Close()
     
    m_isBtnAddClicked= False
     
     
    Dim temp As Integer = CType(m_CurStageNo, Integer)
     
    if (temp+1 > 20)
    {
    lbxStage.SelectedIndex = 0
    }
    else
    {

    lbxStage.SelectedIndex = temp
    }
    lbxStage.SelectedIndex = temp-1
     
    ' MessageBox.Show("Number of records deleted = " + cmdresults.ToString());
     
    }
      

  2.   

    建议到http://prj.csdn.net 发个贴招标,估计 500-2000 元就搞定了
      

  3.   

    在VB6里面,使用ADO访问数据库,在C#里面使用ADO.NET。模型略有不同,所以理解了意思,照着改写即可。
      

  4.   

    C#转成VB.Net有很多的工具可以实现,转成VB6,需要按自己理解的改。
    就上面的代码而言就是执行了Connection的打开,执行了SqlCommand,DataReader,在VB6中可以用对应的Connectoin及RecordSet完成