Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I am trying to dispaly database values based on the combobox selection and i get this error "Data is null. this method cannot be called on null values"

I am trying to dispaly database values based on the combobox selection and i get this error "Data is null. this method cannot be called on null values"

Scheduled Pinned Locked Moved C#
databasehelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10307097
    wrote on last edited by
    #1

    this is my code private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { if (connect.State == ConnectionState.Open) { connect.Close(); } connect.Open(); String query = "select * from V_General_Books where FileName= '" + FileNameComboBox.Text + "'";// '" + textBox2.Text + "' and UserName= '" + textBox3.Text + "' "; cmd = new SqlCommand(query, connect); dr = cmd.ExecuteReader(); if(dr.Read()) { string bookid = dr.GetInt32(10).ToString(); BookIDTextBox.Text = bookid; string generalid = dr.GetInt32(0).ToString(); GeneralIDTextBox.Text = generalid; string isbn = dr.GetString(12); ISBNTextBox.Text = isbn; string author = dr.GetString(11); AuthorNameTextBox.Text = author; string genre = dr.GetString(16); GenreTextBox.Text = genre; byte[] x = (byte[])dr[8]; MemoryStream ms = new MemoryStream(x); pictureBox1.Image = Image.FromStream(ms); string series = dr.GetString(15); SeriesTextBox.Text = series; string year = dr.GetString(14); YearOfPublicationTextBox.Text = year; string dateacquired = dr.GetString(9); DateAcquiredTextBox.Text = dateacquired; string filename = dr.GetString(1); FileNameTextBox.Text = filename; string filepath = dr.GetString(2); FilePathTextBox.Text = filepath; string length = dr.GetString(5); MediaLengthTextBox.Text = length; string type = dr.GetString(6); MediaTypeTextBox.Text = type; string subtype = dr.GetString(7); MediaSubTypeTextBox.Text = subtype; DateTime dateadded = dr.GetDateTime(4); DateAddedDateTimePicker.MaxDate = dateadded; string filesize

    P L W 3 Replies Last reply
    0
    • U User 10307097

      this is my code private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { if (connect.State == ConnectionState.Open) { connect.Close(); } connect.Open(); String query = "select * from V_General_Books where FileName= '" + FileNameComboBox.Text + "'";// '" + textBox2.Text + "' and UserName= '" + textBox3.Text + "' "; cmd = new SqlCommand(query, connect); dr = cmd.ExecuteReader(); if(dr.Read()) { string bookid = dr.GetInt32(10).ToString(); BookIDTextBox.Text = bookid; string generalid = dr.GetInt32(0).ToString(); GeneralIDTextBox.Text = generalid; string isbn = dr.GetString(12); ISBNTextBox.Text = isbn; string author = dr.GetString(11); AuthorNameTextBox.Text = author; string genre = dr.GetString(16); GenreTextBox.Text = genre; byte[] x = (byte[])dr[8]; MemoryStream ms = new MemoryStream(x); pictureBox1.Image = Image.FromStream(ms); string series = dr.GetString(15); SeriesTextBox.Text = series; string year = dr.GetString(14); YearOfPublicationTextBox.Text = year; string dateacquired = dr.GetString(9); DateAcquiredTextBox.Text = dateacquired; string filename = dr.GetString(1); FileNameTextBox.Text = filename; string filepath = dr.GetString(2); FilePathTextBox.Text = filepath; string length = dr.GetString(5); MediaLengthTextBox.Text = length; string type = dr.GetString(6); MediaTypeTextBox.Text = type; string subtype = dr.GetString(7); MediaSubTypeTextBox.Text = subtype; DateTime dateadded = dr.GetDateTime(4); DateAddedDateTimePicker.MaxDate = dateadded; string filesize

      P Offline
      P Offline
      Purna Chandra Rao Chamidisetty
      wrote on last edited by
      #2

      Check SQL query in SQL server query wizard. The problem is with the SQL query. Whatever the query you written is not fetching any data from database. That is the reason why it's saying no data available.

      Cheers, Purna Chandra Rao.Ch

      1 Reply Last reply
      0
      • U User 10307097

        this is my code private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { if (connect.State == ConnectionState.Open) { connect.Close(); } connect.Open(); String query = "select * from V_General_Books where FileName= '" + FileNameComboBox.Text + "'";// '" + textBox2.Text + "' and UserName= '" + textBox3.Text + "' "; cmd = new SqlCommand(query, connect); dr = cmd.ExecuteReader(); if(dr.Read()) { string bookid = dr.GetInt32(10).ToString(); BookIDTextBox.Text = bookid; string generalid = dr.GetInt32(0).ToString(); GeneralIDTextBox.Text = generalid; string isbn = dr.GetString(12); ISBNTextBox.Text = isbn; string author = dr.GetString(11); AuthorNameTextBox.Text = author; string genre = dr.GetString(16); GenreTextBox.Text = genre; byte[] x = (byte[])dr[8]; MemoryStream ms = new MemoryStream(x); pictureBox1.Image = Image.FromStream(ms); string series = dr.GetString(15); SeriesTextBox.Text = series; string year = dr.GetString(14); YearOfPublicationTextBox.Text = year; string dateacquired = dr.GetString(9); DateAcquiredTextBox.Text = dateacquired; string filename = dr.GetString(1); FileNameTextBox.Text = filename; string filepath = dr.GetString(2); FilePathTextBox.Text = filepath; string length = dr.GetString(5); MediaLengthTextBox.Text = length; string type = dr.GetString(6); MediaTypeTextBox.Text = type; string subtype = dr.GetString(7); MediaSubTypeTextBox.Text = subtype; DateTime dateadded = dr.GetDateTime(4); DateAddedDateTimePicker.MaxDate = dateadded; string filesize

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Firstly, you should not use string concatenation in your query string. Read http://bobby-tables.com/about.html[^], and use proper parameterised queries. Secondly, you need to check the result of FileNameComboBox.Text, and indeed, the remainder of that statement to verify that you have actiually created a valid query.

        Veni, vidi, abiit domum

        1 Reply Last reply
        0
        • U User 10307097

          this is my code private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { if (connect.State == ConnectionState.Open) { connect.Close(); } connect.Open(); String query = "select * from V_General_Books where FileName= '" + FileNameComboBox.Text + "'";// '" + textBox2.Text + "' and UserName= '" + textBox3.Text + "' "; cmd = new SqlCommand(query, connect); dr = cmd.ExecuteReader(); if(dr.Read()) { string bookid = dr.GetInt32(10).ToString(); BookIDTextBox.Text = bookid; string generalid = dr.GetInt32(0).ToString(); GeneralIDTextBox.Text = generalid; string isbn = dr.GetString(12); ISBNTextBox.Text = isbn; string author = dr.GetString(11); AuthorNameTextBox.Text = author; string genre = dr.GetString(16); GenreTextBox.Text = genre; byte[] x = (byte[])dr[8]; MemoryStream ms = new MemoryStream(x); pictureBox1.Image = Image.FromStream(ms); string series = dr.GetString(15); SeriesTextBox.Text = series; string year = dr.GetString(14); YearOfPublicationTextBox.Text = year; string dateacquired = dr.GetString(9); DateAcquiredTextBox.Text = dateacquired; string filename = dr.GetString(1); FileNameTextBox.Text = filename; string filepath = dr.GetString(2); FilePathTextBox.Text = filepath; string length = dr.GetString(5); MediaLengthTextBox.Text = length; string type = dr.GetString(6); MediaTypeTextBox.Text = type; string subtype = dr.GetString(7); MediaSubTypeTextBox.Text = subtype; DateTime dateadded = dr.GetDateTime(4); DateAddedDateTimePicker.MaxDate = dateadded; string filesize

          W Offline
          W Offline
          WuRunZhe
          wrote on last edited by
          #4

          Well, which statement occur that error? If you don't know where it is, debug it and get exactly error statement. And before rerun it, you have to check your sql express again. :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups