Click here to Skip to main content
16,016,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every one ,
i have done a windows form which contains two textboxes , first has the word , and the second should has the meaning of that word .
i have a button , when it is clicked it will but the meaning in textbox2 with respect to the word in textbox1 , but i does not perform ?? the error is : Child list for field audio1 cannot be created.

i have used sqlserver & visual studio 2010

this is my code :
C#
private void btntranslate_Click_1(object sender, EventArgs e)
{
    if (textBox1.Text == " ")
    {
        MessageBox.Show(" There is no word to translated! ");
    }
    else
    {
        string constring = "Data Source=.;Initial Catalog=speakerpro;Integrated Security=True";
        string concom= "select mean from [audio1] where word = ' " + textBox1.Text + " ' ;";
        SqlConnection con = new SqlConnection(constring);
        
        SqlCommand com = new SqlCommand(concom , con);
        SqlDataAdapter adp = new SqlDataAdapter();
        DataTable dt = new DataTable();
        con.Open();
        adp.SelectCommand = com;
        adp.Fill(dt);
        textBox2.DataBindings.Add("Text", dt , "audio1.mean");
        SqlDataReader dr = com.ExecuteReader();
        con.Close();
    }
}

is there any problem in my code ??? guide me ,please


[Edit member="Tadit"]
Corrected formatting issues.
Added pre tags.
[/Edit]
Posted
v3

just change the code line

textBox2.DataBindings.Add("Text", dt , "audio1.mean");

to

textBox2.Text= dt.Rows[0]["mean"].ToString();
 
Share this answer
 
C#
Try 

textBox2.DataBindings.Add("Text",dt,"mean");
 
Share this answer
 
C#
private DataTable getmeaning(text1)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("mean", typeof(string));


            if (conn.State.ToString() == "Closed")
            {
                conn.Open();
            }

            SqlCommand newCmd = conn.CreateCommand();
            newCmd.Connection = conn;
            newCmd.CommandType = CommandType.Text;
            newCmd.CommandText = "select mean from [audio1] where word = ' " + text1 + " ' ;";

            SqlDataReader dr = newCmd.ExecuteReader();
            while (dr.Read())
            {

                dt.Rows.Add(dr["mean"]);
            }
            conn.Close();

            return dt;
        }

then call the method like this....

C#
DataTable dt = getmeaning(textBox1.Text);
if(dt.Rows.Count > 0)
{
DataView dv = new DataView(dt);
textBox2.Text = dv[0]["mean"].ToString();
}
 
Share this answer
 
v2
Comments
Me is Needer 9-Jul-14 17:21pm    
thanx alot Mr Hard , i have pasted the code in my program , there are no error but i don't know why it doesn't appear any result in textbox2 :( :( :( ?!!!

Problems, which I can see



  1. Use paramterized Query instead of inline Queries to avoid SQLInjection attack. More at - could not open sql server connection[^]
  2. No need to open or close the Connection while using SqlDataAdapter. SqlDataAdapter does these automatically for you.
  3. You have declared a SqlDataReader at last, which is not needed at all.
 
Share this answer
 
Comments
Me is Needer 30-Jun-14 16:28pm    
thanks for u , but i also face the same problem :( ?? why !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900