Similar Threads:
1.Error "Cast from type 'DataRowView' to type 'String' is not va
Bart,
Thank you very much. Using the DataRelation worked. I just had to specify
the "RelationName" attribute of my DataRelation:
DataGrid1.DataSource = MyDataSet.Tables(0)
DataGrid1.DataMember = MyDataRelation.RelationName
Richard
"Bart Mermuys" wrote:
> Hi,
>
> "Richard Mueller" < XXXX@XXXXX.COM > wrote in
> message news: XXXX@XXXXX.COM ...
> > I've seen this problem posted several times, but have not yet seen a
> > solution. I make a connection to a SQL database and use a DataAdapter
> > object
> > to fill a DataSet object with several tables. A DataRelation object links
> > the
> > tables by an ID column. I bind the parent table to a combo box and a child
> > table to a DataGrid control using a DataView object. I want the DataGrid
> > control to reflect the selection in the combo box. For the combo box,
> > DisplayMember is a text string while ValueMember is the ID field
> > (integer).
> > In brief:
> >
> > Private Sub Form1_Load(....)
> > ' Connect to database, populate Tables in DataSet,
> > ' setup DataViews, and define DataRelations.
> > Call Populate()
> >
> > ComboBox1.DataSource = MyDataSet.Tables(0)
> > ComboBox1.DisplayMember = MyDataSet.Tables(0).Columns(1).ColumnName
> > ComboBox1.ValueMember = MyDataSet.Tables(0).Columns(0).ColumnName
> > Me.BindingContext(MyDataSet.Tables(0)).Position = 0
> >
> > Dim strFilter As String
> > strFilter = "ID = " & ComboBox1.SelectedValue
> > MyDataView.RowFilter = strFilter
> > DataGrid1.DataSource = MyDataView
> > End Sub
> >
> > Private Sub ComboBox1_SelectedValueChanged(....)
> > Dim strFilter As String
> > If (ComboBox1.SelectedIndex <> -1) Then
> > strFilter = "ID = " & ComboBox1.SelectedValue
> > MyDataView.RowFilter = strFilter
> > End If
> > End Sub
> >
> > Strangely, the code works if I comment out the
> > ComboBox1_SelectedValueChanged sub. I can hard code in Form1_Load to
> > select
> > the first (index=0), or any other item in the combo box, and the DataGrid
> > reflects the correct item. But of course I cannot select another item in
> > the
> > combo box and have the DataGrid reflect this. The error is raised in
> > CombBox1_SelectedValueChanged on the statement:
> >
> > strFilter = "ID = " & ComboBox1.SelectedValue
> >
> > and the error is "Cast from type 'DataRowView' to type 'String' is not
> > valid. I've tried to use ToString and CStr to no avail. I think the key is
> > that I assign a DataSource to the combo box, plus the DisplayMember and
> > ValueMember properites, then attempt to use the SelectedValue property
> > when
> > the user makes a selection. Any ideas?
>
> You're probely getting this error because SelectedValueChanged fires after
> setting the ComboBox.DataSource but before you have set the
> ComboBox.ValueMember. So at that point SelectedValue returns a DataRowView.
> So you could change it to:
>
> Private Sub ComboBox1_SelectedValueChanged(....)
> Dim strFilter As String
> If (ComboBox1.SelectedIndex <> -1) AndAlso _
> (ComboBox1.ValueMember<>"") Then
> strFilter = "ID = " & ComboBox1.SelectedValue
> MyDataView.RowFilter = strFilter
> End If
> End Sub
>
> BUT, if you have a DataRelation between the two DataTables, then you don't
> need to do that, you can let the child rows be _automatically_ filtered.
> All you have to do is bind the DataGrid to the same DataSource as the
> ComboBox and set DataGrid.DataMember to the name of the DataRelation between
> them:
>
> Private Sub Form1_Load(....)
> ' Connect to database, populate Tables in DataSet,
> ' setup DataViews, and define DataRelations.
> Call Populate()
>
> ComboBox1.DataSource = MyDataSet.Tables(0)
> ComboBox1.DisplayMember = MyDataSet.Tables(0).Columns(1).ColumnName
> ComboBox1.ValueMember = MyDataSet.Tables(0).Columns(0).ColumnName
>
> DataGrid1.DataSource = MyDataSet.Tables(0)
> DataGrid1.DataMember = "NameOfRelationBetweenTables"
> End Sub
>
> This way the DataGrid should be auto filtered when you change ComboBox
> selection.
>
>
> HTH,
> Greetings
>
>
>
> > Note. My code is based on "Using a Data Set with Tables in a Parent-Child
> > Relationship" from Chapter 10 (pg. 402-408) of "Programming Microsoft SQL
> > Server 2000 with Microsoft Visual Basic .NET" by Rick Dobson.
> >
> > Richard
>
>
>
>
>
>
2.Output SqlParameter Returns NULL Value When Procedure Assigns a Va
I am encountering the following problem with a call to a stored procedure
from C# code.
The stored procedure looks like this:
ALTER PROCEDURE sproc
@id1 int,
@id2 int,
@trans_date datetime,
@flag1 bit output,
@result int Output
AS
.
.
.
Set @flag1 = (SELECT flag From MyTable
Where id = @id2)
-- A record is found and debugger shows @flag1 has a value
.
.
.
Return 0
The C# code:
sqlCmdData.CommandText = "sproc";
sqlCmdData.Parameters.Clear();
sqlCmdData.Parameters.AddWithValue("@id1", _id1);
sqlCmdData.Parameters.AddWithValue("@id2", _id2);
sqlCmdData.Parameters.AddWithValue("@trans_date", DateTime.Now);
SqlParameter sqlParmFlag = new SqlParameter("@flag1", SqlDbType.Bit);
sqlParmFlag.Direction = ParameterDirection.Output;
sqlCmdData.Parameters.Add(sqlParmFlag);
SqlParameter sqlParmResult = new SqlParameter("@result", SqlDbType.Int);
sqlParmResult.Direction = ParameterDirection.Output;
sqlCmdData.Parameters.Add(sqlParmResult);
SqlDataReader dr = sqlCmdData.ExecuteReader();
int _status = Convert.ToInt32(sqlParmResult.Value); // This works OK
bool flag = (bool)sqlParmFlag.Value; // sqlParmFlag.Value is always NULL
This throws a NULL exception.
Any ideas on what may be happening here?
I would appreciate any help.
Thanks,
Eagle
3.OracleCommadbuilder: Exception: Parameter 'p1': No size set for va
Hello,
I am re-raising this post as we have a developer here running into the same issue. Is this a bug or a feature? Are there any similar bugs or features of other datatypes that we should be aware of?
Thanks!
"Peter Meinl" wrote:
> When updating an Oracle Varchar2 column with an empty string "" using the
> OracleCommandBuilder generated UpdateCommand the follwing error is thrown:
> "Parameter 'p1': No size set for variable length data type: String."
>
> Is this a bug in the OracleCommandBuilder? Is there an elegant workaround?
>
> Updating with DBNull.Value instead of an empty string does not throw the
> above error.
>
>
>
4.when deleting a row from a datagrid how do i get the cell ( 0 ) va
5.Jr/Mid Level .Net Developer(s) Needed In Stafford, VA
6. Need help: Call server side Stored Procedure and get the return va
7. How to validate one control based on the truth value of another va
8. Server-side events do not fire the first time after client-side va