hello everyone ;
what is the syntax of list box in insert querry. i am using c-sharp .
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Aug 7, 2010, 11:54 PM
Is it working now!.Iam attaching a sample application which i did it.I used Ms-access db which is located in bin folder.Check it out.
Thanks
Satyapriya NayakPosted Aug 7, 2010, 1:09 PM
Change it in you ADD Button and try this .It will work sure....
private void button_ADD_Click(object sender, EventArgs e)
{
listBox_selected_services.SelectedIndex = 0;
listBox_lab_charges.SelectedIndex = 0;
MY_SQL_NEW_QUR.Access("insert into laboratory([laboratoryrecieptid],[patientid],[patientname],[doctorname],[departmentname],[laboratoryselectedservices],[laboratorycharges],[totalcharges])values('" + textBox_laboratory_reciept_id.Text + "','" + textBox_patient_id.Text + "','" + textBox_patient_name.Text + "','" + textBox_doctor_name.Text + "','" + textBox_department_name.Text + "','" + listBox_selected_services.SelectedItem.ToString() + "','" + listBox_lab_charges.SelectedItem.ToString() + "','" + textBox_total_charges.Text + "')",connection.My_Get());
}
Thanks
theLizardPosted Aug 7, 2010, 6:16 AM
listBox_lab_charges.SelectedValue.ToString()
sumaira manzoor hussain khanPosted Aug 7, 2010, 4:33 AM
ok. i have been sent my application to you .
thanks
sumaira manzoor hussain khanPosted Aug 7, 2010, 4:31 AM
the error exist in the insert query of laboratory module .
sumaira manzoor hussain khanPosted Aug 7, 2010, 4:25 AM
my application is very heavy .
Satyapriya NayakPosted Aug 7, 2010, 4:22 AM
Can you attach your application i want to check it over here in my system.
Thanks
sumaira manzoor hussain khanPosted Aug 7, 2010, 1:19 AM
i add '"+listBox_selected_services.Text+"' and '"+listBox_lab_charges.Text+"' in my query . but there is not effect. the another thing is , i am using c-sharp express edition and my project is form based.
my query generate this type of error .
Error 1 'object' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Satyapriya NayakPosted Aug 6, 2010, 1:39 PM
listBox_selected_services.Text change it to '"+listBox_selected_services.Text+"'
listBox_lab_charges.Text change it to '"+listBox_lab_charges.Text+"'
Change it in your query and test it ......
Thanks
Satyapriya NayakPosted Aug 6, 2010, 12:39 PM
The application i wrote is webapplication not windows app.So check it out your app is win or web.
Thanks
sumaira manzoor hussain khanPosted Aug 6, 2010, 10:28 AM
your code generate this type of error .
Error 1 'object' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) D:\hospital management system\hospital management\hospital management\laboratory.cs 58 420 hospital management
sumaira manzoor hussain khanPosted Aug 6, 2010, 10:24 AM
i am sending my insert query . the error are occur in the list box syntax. the wrong syntax is in orange color. actually, my problem is syntax of list box in insert query .
MY_SQL_NEW_QUR.Access("insert into laboratory([laboratoryrecieptid],[patientid],[patientname],[doctorname],[departmentname],[laboratoryselectedservices],[laboratorycharges],[totalcharges])values('"+textBox_laboratory_reciept_id.Text+"','"+textBox_patient_id.Text+"','"+textBox_patient_name.Text+"','"+textBox_doctor_name.Text+"','"+textBox_department_name.Text+"','"+ listBox_selected_services.SelectedItem.Text+"','"+listBox_lab_charges.SelectedItem.Text+"','"+textBox_total_charges.Text+"')",connection.My_Get());
sumaira manzoor hussain khanPosted Aug 6, 2010, 10:18 AM
sir, i wrote the listbox1.selecteditem in my code but .Text is missing in my code. it means .Text is not in the library
Satyapriya NayakPosted Aug 6, 2010, 9:12 AM
I wonder what you are looking for the solution,first the question iam not very clear.I mean to say that in listbox previously items are bound to it or not if yes i have a solution given below
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ListBox1.Items.Add("HR");
ListBox1.Items.Add("IT");
ListBox1.Items.Add("MK");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "insert into emp values('" + TextBox1.Text + "','" + ListBox1.SelectedItem.Text + "')";
cmd = new SqlCommand(str, conn);
cmd.ExecuteNonQuery();
conn.Close();
Response.Write("Records Inserted");
clear();
}
void clear()
{
TextBox1.Text = "";
}
}
Iam attaching a sample program you run it to get the desired output.
Thanks
If this helps you mark it as Accepted Answer
sumaira manzoor hussain khanPosted Aug 6, 2010, 5:41 AM
please, you will check my querry . because i apply listbox syntax directly in my code . but my query give error to me.
this is my query
MY_SQL_NEW_QUR.Access("insert into laboratory([laboratoryrecieptid],[patientid],[patientname],[doctorname],[departmentname],[laboratoryselectedservices],[laboratorycharges],[totalcharges])values('"+textBox_laboratory_reciept_id.Text+"','"+textBox_patient_id.Text+"','"+textBox_patient_name.Text+"','"+textBox_doctor_name.Text+"','"+textBox_department_name.Text+"',listBox_selected_services.Text, listBox_lab_charges.Text,'"+textBox_total_charges.Text+"')",connection.My_Get());
Koteswararao MallisettiPosted Aug 6, 2010, 5:23 AM
it will give the list box selected item textvalue you directly use it in the insert Query