Hi ,
I need help with select staement.I am trying to to look for a word in column word .If i find that word then then show a message box that this word exist in databse.Can anyone help me with this.my code is something like this
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) return; // column header clicked - do nothing // get the row just clicked
DataRowView drv = dataGridView2.Rows[e.RowIndex].DataBoundItem as DataRowView;
if (drv != null)
{
//convert row to strongly typed row from dataset
DataRow row = drv.Row as DataRow;
string myString;
string mystring2;
SqlConnection cn = new SqlConnection(@"Server=208.124.179.197;Database=RTLUser;UID=sa;");
SqlDataAdapter da = new SqlDataAdapter();
SqlCommandBuilder cmdBuilder;
DataSet ds = new DataSet();
cn.Open();
mystring2 = @"SELECT word FROM wordsTbl where word = ('"+(string)row["word"]+"')";
SqlCommand myCmd = new SqlCommand(mystring2, cn);
myCmd.ExecuteNonQuery();
cn.Close();
if (myCmd == row["word"])
{
MessageBox.Show(row["word"] + " already exist in your personal dictionary");
}
else
{
cn.Open();
myString = @"INSERT INTO wordsTbl(word) Values('" + (string)row["word"] + "')";
SqlCommand myCmd2 = new SqlCommand(myString, cn);
myCmd2.ExecuteNonQuery();
cn.Close();
MessageBox.Show(row["word"] + "is added to your personal dictionary");
richTextBox1.Text = "Word:" + row["word"];
//}
//}
}