using System;
using System.Data;
using System.Data.OleDb;namespace Materiel {
/// <summary>
/// 物料
/// </summary>
public class Item {
public Item() {} /// Public constants for column positions on the Item table.
public const int Item_no = 0;
public const int Note = 1;
public const int Unit = 2; /// <summary>
/// Inserts a record into the Item table.
/// </summary>
public static void Insert(string item_no, string note, string unit) {
using (OleDbConnection connection = new OleDbConnection(SystemFramework.ApplicationConfiguration.ConnectionString)) {
using (OleDbCommand command = new OleDbCommand()) {
// Initialize the command
command.Connection = connection;
command.CommandText = "saItemInsert";
command.CommandType = CommandType.StoredProcedure; // Create the parameters and append them to the command object
command.Parameters.Add(new OleDbParameter("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, false, 0, 0, "Item_no", DataRowVersion.Proposed, item_no));
command.Parameters.Add(new OleDbParameter("@note", OleDbType.VarChar, 25, ParameterDirection.Input, false, 0, 0, "note", DataRowVersion.Proposed, note));
command.Parameters.Add(new OleDbParameter("@unit", OleDbType.VarChar, 10, ParameterDirection.Input, false, 0, 0, "unit", DataRowVersion.Proposed, unit)); // Open the database connection and execute the query
connection.Open();
command.ExecuteNonQuery();
}
}
}
/// <summary>
/// Updates a record in the Item table.
/// </summary>
public static void Update(string item_no, string note, string unit) {
using (OleDbConnection connection = new OleDbConnection(SystemFramework.ApplicationConfiguration.ConnectionString)) {
using (OleDbCommand command = new OleDbCommand()) {
// Initialize the command
command.Connection = connection;
command.CommandText = "saItemUpdate";
command.CommandType = CommandType.StoredProcedure; // Create the parameters and append them to the command object
command.Parameters.Add(new OleDbParameter("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, false, 0, 0, "Item_no", DataRowVersion.Proposed, item_no));
command.Parameters.Add(new OleDbParameter("@note", OleDbType.VarChar, 25, ParameterDirection.Input, false, 0, 0, "note", DataRowVersion.Proposed, note));
command.Parameters.Add(new OleDbParameter("@unit", OleDbType.VarChar, 10, ParameterDirection.Input, false, 0, 0, "unit", DataRowVersion.Proposed, unit)); // Open the database connection and execute the query
connection.Open();
command.ExecuteNonQuery();
}
}
}
/// <summary>
/// Deletes a record from the Item table by a composite primary key.
/// </summary>
public static void Delete(string item_no) {
using (OleDbConnection connection = new OleDbConnection(SystemFramework.ApplicationConfiguration.ConnectionString)) {
using (OleDbCommand command = new OleDbCommand()) {
// Initialize the command
command.Connection = connection;
command.CommandText = "saItemDelete";
command.CommandType = CommandType.StoredProcedure; // Create and append the parameters
command.Parameters.Add(new OleDbParameter("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, false, 0, 0, "Item_no", DataRowVersion.Proposed, item_no)); // Open the database connection and execute the query
connection.Open();
command.ExecuteNonQuery();
}
}
}
/// <summary>
/// Selects a single record from the Item table.
/// </summary>
public static IDataReader Select(string item_no) {
OleDbConnection connection = new OleDbConnection(SystemFramework.ApplicationConfiguration.ConnectionString); try {
using (OleDbCommand command = new OleDbCommand()) {
// Initialize the command
command.Connection = connection;
command.CommandText = "saItemSelect";
command.CommandType = CommandType.StoredProcedure; // Create the parameters and append them to the command object
command.Parameters.Add(new OleDbParameter("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, false, 0, 0, "Item_no", DataRowVersion.Proposed, item_no)); // Open the connection, execute the query, and return the result
connection.Open();
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
} catch {
// Close the connection object and rethrow the exception
connection.Close();
throw;
}
}
/// <summary>
/// Selects all records from the Item table.
/// </summary>
public static IDataReader SelectAll() {
OleDbConnection connection = new OleDbConnection(SystemFramework.ApplicationConfiguration.ConnectionString); try {
using (OleDbCommand command = new OleDbCommand()) {
// Initialize the command
command.Connection = connection;
command.CommandText = "saItemSelectAll";
command.CommandType = CommandType.StoredProcedure; // Open the connection, execute the query, and return the result
connection.Open();
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
} catch {
// Close the connection object and rethrow the exception
connection.Close();
throw;
}
}
/// <summary>
/// 查询所有的物料
/// </summary>
public static DataTable SelectItem() 
{
DataTable table = new DataTable("Item");
OleDbConnection connection = new OleDbConnection(SystemFramework.ApplicationConfiguration.ConnectionString); try 
{
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Item",connection);
adapter.Fill(table);

catch 
{
// Close the connection object and rethrow the exception
connection.Close();
throw new Exception("数据查询失败!");
}
return table;
}

/// <summary>
/// 查询所有的物料
/// </summary>
public static DataTable OneItem(string strItemNo) 
{
DataTable table = new DataTable("Item");
OleDbConnection connection = new OleDbConnection(SystemFramework.ApplicationConfiguration.ConnectionString); try 
{
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Item WHERE Item_no = '" + strItemNo.Replace("'","''") + "'",connection);
adapter.Fill(table);

catch 
{
// Close the connection object and rethrow the exception
connection.Close();
throw new Exception("数据查询失败!");
}
return table;
}
}
}

解决方案 »

  1.   

    http://www.developerfusion.com/utilities/convertcsharptovb.aspxConvert C# to VB.NET
      

  2.   

    Imports System 
    Imports System.Data 
    Imports System.Data.OleDb 
    Namespace Materiel  Public Class Item    Public Sub New() 
       End Sub 
       Public Const Item_no As Integer = 0 
       Public Const Note As Integer = 1 
       Public Const Unit As Integer = 2    Public Shared Sub Insert(ByVal item_no As String, ByVal note As String, ByVal unit As String) 
         ' Using 
         Dim connection As OleDbConnection = New OleDbConnection (SystemFramework.ApplicationConfiguration.ConnectionString) 
         ' Inside 
         ' Using 
         Dim command As OleDbCommand = New OleDbCommand () 
         ' Inside 
         command.Connection = connection 
         command.CommandText = "saItemInsert" 
         command.CommandType = CommandType.StoredProcedure 
         command.Parameters.Add(New OleDbParameter ("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, False, 0, 0, "Item_no", DataRowVersion.Proposed, item_no)) 
         command.Parameters.Add(New OleDbParameter ("@note", OleDbType.VarChar, 25, ParameterDirection.Input, False, 0, 0, "note", DataRowVersion.Proposed, note)) 
         command.Parameters.Add(New OleDbParameter ("@unit", OleDbType.VarChar, 10, ParameterDirection.Input, False, 0, 0, "unit", DataRowVersion.Proposed, unit)) 
         connection.Open() 
         command.ExecuteNonQuery() 
         ' End Using 
         ' End Using 
       End Sub    Public Shared Sub Update(ByVal item_no As String, ByVal note As String, ByVal unit As String) 
         ' Using 
         Dim connection As OleDbConnection = New OleDbConnection (SystemFramework.ApplicationConfiguration.ConnectionString) 
         ' Inside 
         ' Using 
         Dim command As OleDbCommand = New OleDbCommand () 
         ' Inside 
         command.Connection = connection 
         command.CommandText = "saItemUpdate" 
         command.CommandType = CommandType.StoredProcedure 
         command.Parameters.Add(New OleDbParameter ("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, False, 0, 0, "Item_no", DataRowVersion.Proposed, item_no)) 
         command.Parameters.Add(New OleDbParameter ("@note", OleDbType.VarChar, 25, ParameterDirection.Input, False, 0, 0, "note", DataRowVersion.Proposed, note)) 
         command.Parameters.Add(New OleDbParameter ("@unit", OleDbType.VarChar, 10, ParameterDirection.Input, False, 0, 0, "unit", DataRowVersion.Proposed, unit)) 
         connection.Open() 
         command.ExecuteNonQuery() 
         ' End Using 
         ' End Using 
       End Sub    Public Shared Sub Delete(ByVal item_no As String) 
         ' Using 
         Dim connection As OleDbConnection = New OleDbConnection (SystemFramework.ApplicationConfiguration.ConnectionString) 
         ' Inside 
         ' Using 
         Dim command As OleDbCommand = New OleDbCommand () 
         ' Inside 
         command.Connection = connection 
         command.CommandText = "saItemDelete" 
         command.CommandType = CommandType.StoredProcedure 
         command.Parameters.Add(New OleDbParameter ("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, False, 0, 0, "Item_no", DataRowVersion.Proposed, item_no)) 
         connection.Open() 
         command.ExecuteNonQuery() 
         ' End Using 
         ' End Using 
       End Sub    Public Shared Function Select(ByVal item_no As String) As IDataReader 
         Dim connection As OleDbConnection = New OleDbConnection (SystemFramework.ApplicationConfiguration.ConnectionString) 
         Try 
           ' Using 
           Dim command As OleDbCommand = New OleDbCommand () 
           ' Inside 
           command.Connection = connection 
           command.CommandText = "saItemSelect" 
           command.CommandType = CommandType.StoredProcedure 
           command.Parameters.Add(New OleDbParameter ("@Item_no", OleDbType.VarChar, 25, ParameterDirection.Input, False, 0, 0, "Item_no", DataRowVersion.Proposed, item_no)) 
           connection.Open() 
           Return command.ExecuteReader(CommandBehavior.CloseConnection) 
           ' End Using 
         Catch generatedExceptionVariable0 As 
           connection.Close() 
           Throw 
         End Try 
       End Function    Public Shared Function SelectAll() As IDataReader 
         Dim connection As OleDbConnection = New OleDbConnection (SystemFramework.ApplicationConfiguration.ConnectionString) 
         Try 
           ' Using 
           Dim command As OleDbCommand = New OleDbCommand () 
           ' Inside 
           command.Connection = connection 
           command.CommandText = "saItemSelectAll" 
           command.CommandType = CommandType.StoredProcedure 
           connection.Open() 
           Return command.ExecuteReader(CommandBehavior.CloseConnection) 
           ' End Using 
         Catch generatedExceptionVariable0 As 
           connection.Close() 
           Throw 
         End Try 
       End Function    Public Shared Function SelectItem() As DataTable 
         Dim table As DataTable = New DataTable ("Item") 
         Dim connection As OleDbConnection = New OleDbConnection (SystemFramework.ApplicationConfiguration.ConnectionString) 
         Try 
           Dim adapter As OleDbDataAdapter = New OleDbDataAdapter ("SELECT * FROM Item", connection) 
           adapter.Fill(table) 
         Catch generatedExceptionVariable0 As 
           connection.Close() 
           Throw New Exception ("数据查询失败!") 
         End Try 
         Return table 
       End Function    Public Shared Function OneItem(ByVal strItemNo As String) As DataTable 
         Dim table As DataTable = New DataTable ("Item") 
         Dim connection As OleDbConnection = New OleDbConnection (SystemFramework.ApplicationConfiguration.ConnectionString) 
         Try 
           Dim adapter As OleDbDataAdapter = New OleDbDataAdapter ("SELECT * FROM Item WHERE Item_no = '" + strItemNo.Replace("'", "''") + "'", connection) 
           adapter.Fill(table) 
         Catch generatedExceptionVariable0 As 
           connection.Close() 
           Throw New Exception ("数据查询失败!") 
         End Try 
         Return table 
       End Function 
     End Class 
    End Namespace
      

  3.   

    名称:
    地址:http://www.aspalliance.com/aldotnet/examples/translate.aspx 
    描述:c#翻译为vb.net,提供一个文本框,将你的C#源代码贴进去,就可以帮你翻译成VB.NET语法。