Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

query realted to command

$
0
0

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;
using System.Data.SqlClient;
using System.Configuration;

namespace Log_In_Form
{
    public partial class Search_Issue_Books : Form
    {
        DataSet ds;
        //SqlDataReader dr;
        //bool blresult;

        public Search_Issue_Books()
        {
            InitializeComponent();
        }

        private void button_back_Click(object sender, EventArgs e)
        {
            this.Close();
            Actions act = new Actions();
            act.ShowDialog();
        }

        private void button_search_Click(object sender, System.EventArgs e)
        {
            try
            {
                dataGridView1.DataSource = ds.Tables["Book category"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Library Management", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                Application.Exit();
            }
        }

        private void Search_Issue_Books_Load(object sender,EventArgs e)
        {
                //ds = new DataSet();
                string s = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
                SqlConnection con = new SqlConnection(s);
                con.Open();

                SqlCommand cmd = new SqlCommand("Select * from Search_Books where Book category=@Book category", con);
                //SqlParameter spm1 = new SqlParameter("@Book category", Book_category);
                cmd.Parameters.AddWithValue("@Book category",textBox1.Text);
                //SqlDataReader dr = cmd.ExecuteReader();
                //SqlCommand cmd = new SqlCommand("Select * from Log_in where category=@Category", con);

                //cmd.Parameters.AddWithValue("@Category", Book.category);
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                DataSet ds = new DataSet();
                da.Fill(ds, "Book category");
                dataGridView1.DataSource = ds.Tables[0];



                //if (dr.HasRows)
                //{
                //    dataGridView1.DataSource = ds.Tables["Book category"];
                //}

                //SqlDataAdapter da = new SqlDataAdapter("select * from Search_Books ", con);

                //ds = new DataSet();
                //da.Fill(ds, "Book category");
                //SqlCommandBuilder cmd = new SqlCommandBuilder(da);
                //SqlDataAdapter dr = cmd.ExecuteReader();
        }

        public object dw { get; set; }
    }
}

sir, it is giving the error mentioned below

1. 

Incorrect syntax near 'nvarchar'.
An expression of non-boolean type specified in a context where a condition is expected, near 'category'.

sir body text is not taking the images or links as it is saying that body text cannot contain images until they will verify my account so i m not able to post my table


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>