我想从另一个表列插入值

时间:2019-05-06 05:38:10

标签: c# mysql sql

我有2张这样的桌子,

tbl_motor

Ctrl+F

tbl_employee

webkit-clip-path

但是我有问题。我在寄存器上使用了combo_box。
我的组合框查询是static void Main(string[] args) { Console.WriteLine(IPAddress.IPv6Any); UdpClient udpClient = new UdpClient(); try { udpClient.EnableBroadcast = true; udpClient.Connect("192.168.1.255",80); // Sends a message to the host to which you have connected. Byte[] sendBytes = Encoding.ASCII.GetBytes("#SERVER"); udpClient.Send(sendBytes, sendBytes.Length); //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); // Blocks until a message returns on this socket from a remote host. Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); // Uses the IPEndPoint object to determine which of these two hosts responded. Console.WriteLine("This is the message you received " + returnData.ToString()); Console.WriteLine("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString()); udpClient.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.ReadKey(); } '''

如何将新值插入motor_id motor_types -------------------------- 1 audi 2 Ferrari ,这是我的组合框是字符串 emmmm我的意思是将字符串解析为int。

1 个答案:

答案 0 :(得分:1)

ComboBox可以包含任何类型的对象。您应避免将添加文本设置为项目。添加您的电动机。

您大概有一个这样的班级:

class Motor
{
    public int MotorId { get; set; }
    public string MotorType { get; set; }

    public override string ToString() // Important to override. This will be used to show the text in the combobox
    {
        return this.MotorType;
    }
}

这是您添加Motors并阅读SelectedItem的方式:

// This is your Array which you got from your DB
Motor[] motors = new Motor[]
{
    new Motor() { MotorId = 1, MotorType = "Audi" },
    new Motor() { MotorId = 2, MotorType = "Ferrari" },
};

// We clear old items and add the motors:
this.comboBox1.Items.Clear();
this.comboBox1.Items.AddRange(motors);

// Select something for demonstration
this.comboBox1.SelectedIndex = 1;

// Read the selected item out of the combobox
Motor selectedMotor = this.comboBox1.SelectedItem as Motor; 

// Let's have a look what we got
MessageBox.Show(selectedMotor.MotorId + ": " + selectedMotor.MotorType);