Error msg:"No value given for one or more..."

This is a discussion on Error msg:"No value given for one or more..." within the C# Programming forums, part of the General Programming Boards category; hi, I have a form that needs to update a Db. It is almost identical to another form (working o.k) ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    11

    Error msg:"No value given for one or more..."

    hi,

    I have a form that needs to update a Db. It is almost identical to another form (working o.k)
    doing more or less the same thing
    and yet here I get the following error msg:

    No value given for one or more required parameters

    Line 95: atmovies NewmovTbl=new atmovies();
    Line 96: NewmovTbl.moviesconn.Open();
    Line 97: NewmovTbl.moviesadp.Fill(MoviesDS);
    Line 98:
    Line 99: DataTable MovTable = MoviesDS.Tables["tblmovie"];

    I really can't see why it doesn't work.
    Based on my other form it should work.
    If u could point me to any mistakes
    I'll apreciate it. thanks.

    here is the code:
    Code:
    private static string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Mode=ReadWrite; User ID=Admin; Data Source=C:\\Inetpub\\wwwroot\\DB\\db.mdb;";
    private void Page_Load(object sender, System.EventArgs e)
    {
         LoadMovDG();
    }
    
    private void LoadMovDG()
    {
         DataSet ds = GetAllMovies();
         MovDG.DataSource = ds.Tables[0].DefaultView;
         MovDG.DataBind();
    }
    
    private void MovAddBtn_Click(object sender, System.EventArgs e)
    {
         AddMovie(this.TBName.Text,this.TBCat.Text,this.TBPrice.Text);
    }
    
    private void AddMovie(string name,string cat, string price )
    {
         string sql = "insert into tblmovie movie_name,movie_categoria,movie_price) "+" values ('{0}', '{1}','{2}') ";
         sql = String.Format(sql,name,cat,price);
         UpdateDB(sql);
         LoadMovDG();
    }
    		
    private void UpdateDB(string cmd)
    {
         if(TBName.Text!=null && TBCat.Text!=null && TBPrice.Text!=null )
         {
              DataSet MoviesDS =new DataSet();
              atmovies NewmovTbl=new atmovies();
              NewmovTbl.moviesconn.Open();		     
              NewmovTbl.moviesadp.Fill(MoviesDS);
              DataTable MovTable = MoviesDS.Tables["tblmovie"];
              DataRow CurrentMovie = FindMovie (MoviesDS,TBName.Text);
    				
              if (CurrentMovie==null)
             {		
    	   try
    	   {
    	        OleDbConnection connection = new OleDbConnection(sConn);
    	        connection.Open();
    	        OleDbCommand command = new OleDbCommand();
    	        command.Connection = connection;
    	        command.CommandText = cmd;
    	        command.ExecuteNonQuery();
    	        connection.Close();
    	   }
    	   catch(Exception x)
    	   {
    	       status.Text = x.ToString();
    	       status.Visible=true;			  	       status.Text="error";
                       }
    
              }
              else
             {
    	   status.Visible=true;
    	   status.Text="movie allready exists";
              }
              NewmovTbl.moviesconn.Close();
           }
    }
    
    
    private DataRow FindMovie(DataSet MovDs, string MovName)
    {
          DataTable MovTable = MovDs.Tables["tblmovie"];  	
          foreach (DataRow movie in MovTable.Rows)
          {
              string MName = (string)movie["movie_name"];
              						     
              if (MName == MovName) 
    	{
    		movie1=movie;
    		return movie1;
    	}
          }
          return null;
    }
    
    public static DataSet GetDataSet(string sql)
    {
          DataSet ds = new DataSet();
          OleDbConnection oConn = new OleDbConnection();
          oConn.ConnectionString = sConn;
          oConn.Open();
          OleDbCommand cmd = new OleDbCommand(sql,oConn);
          OleDbDataAdapter da = new OleDbDataAdapter(cmd);
          da.Fill(ds);
          oConn.Close();
          return ds;
    }
    
    public static DataSet GetAllMovies()
    {
          string Ctxt = "SELECT movie_code AS Code,movie_name AS Movie,movie_price AS Price FROM tblmovie";
          DataSet ds = GetDataSet(Ctxt);
          return ds;
    }
    }
    }
    "Cream is not the only thing that floats to the top..."

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    I need to see the table definition to tell you why you got this error.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21