Pls could anyone help me how to get data from combo box with my following code
i used txt_app_code for combo box name.
i used txt_app_code for combo box name.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class frm_Application_Details : Form
{
public ADODB.Connection con = new ADODB.Connection();
public ADODB.Recordset rs = new ADODB.Recordset();
public string ConStr;
public string db_Server;
public string db_port;
public string db;
public string db_User;
public string db_Pass;
public string query;
public frm_Application_Details()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
if (txt_App_Code.Text == "")
{
MessageBox.Show("Please Enter the Application Code");
return;
}
if (txt_App_Name.Text == "") { MessageBox.Show("Please Enter the name"); return; }
if (txt_Start_Date.Text == "") { MessageBox.Show("Please Enter the Date and Time"); return; }
query = "select * from application_m where ApplicationCode='" + txt_App_Code.Text + "'";
rs.Open(query, con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
if (rs.EOF == false)
{
rs.Close();
MessageBox.Show("Application Code is Already used. Please Enter Different Application code");
return;
}
else
{
rs.Close();
query = "Insert Into application_m(ApplicationCode,ApplicationName,StartDate) Values('" + txt_App_Code.Text + "','" + txt_App_Name.Text + "',now())";
rs.Open(query, con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
MessageBox.Show("Application details saved");
}
}
private void frm_Application_Details_Load(object sender, EventArgs e)
{
db_Server = "localhost";
db_port = "3306";
db = "etechdata";
db_User = "root";
db_Pass = "";
ConStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + db_Server + ";PORT=" + db_port + ";DATABASE=" + db + ";UID=" + db_User + ";PWD=" + db_Pass + ";OPTION=3";
//OdbcCon.ConnectionString = ConStr;
try
{
con.Open(ConStr, null, null, 0);
}
catch (System.Data.Odbc.OdbcException Ex)
{
MessageBox.Show("Could not access the database.\r\nPlease make sure you completed the fields with the correct information and try again.\r\n\r\nMore details:\r\n" + Ex.Message, "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Comment