|
I am currently getting an error that I am having a bit of trouble trying to figure out here is the code below that I am working with:
Xaml Code:
<DataGrid Height="418" VerticalAlignment="Top" IsReadOnly="True" Width="846" ItemsSource="{Binding Path=MyDataBinding}" Name="datagrid1" BorderBrush="#FF0C5900" Style="{DynamicResource DataGridStyle1}" Background="#FF1F1F1F" ColumnHeaderHeight="30" ColumnWidth="127" BorderThickness="1,0,0,1" SelectionMode="Single" RowHeight="40" FontSize="14">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<EventSetter Event="MouseDoubleClick" Handler="DataGrid_MouseDoubleClick"/>
</Style>
</DataGrid.RowStyle>
</DataGrid>
private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataGridRow dgr = sender as DataGridRow;
DataRowView drv = dgr.DataContext as DataRowView;
string hybridInfo = drv.Row["HybridInfo"].ToString();
conConnect = new SqlConnection("Data Source=GERRY;Initial Catalog=MMJDB;Integrated Security=True");
SqlCommand cmd = new SqlCommand("SELECT * FROM StrainInfo WHERE HybridInfo=@HybridInfo");
cmd.Connection = conConnect;
cmd.Parameters.AddWithValue("@HybridInfo", hybridInfo);
conConnect.Open();
dAdapter = new SqlDataAdapter(cmd);
DS = new DataSet();
dAdapter.Fill(DS, "MyDataBinding");
datagrid2.ItemsSource = DS.Tables[0].AsDataView();
dAdapter.Dispose();
conConnect.Close();
}
The line of code that is producing the following error:
A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Column 'HybridInfo' does not belong to table MyDataBinding
string hybridInfo = drv.Row["HybridInfo"].ToString();
modified 19-Apr-14 14:59pm.
|
|
|
|
|
Check your MMJDB database table and see if it has a column named HybridInfo.
|
|
|
|
|
Yeah I have a column named HybridInfo that shows up in Visual Studio under the MMJDBDataSet.xsd file and In Sql Server Management Studio.
The HybridInfo Column is under the StrainInfo Table.
modified 19-Apr-14 18:54pm.
|
|
|
|
|
Then you should probably debug your code to find out why your query is not returning the results you expect.
|
|
|
|
|
I have been debugging the code and eve inserted a break point. I even went as far as remaking the entire Database and resetting the Primary Keys.
|
|
|
|
|
Well I sure don't know what to tell you. The error message is very clear and specific. Either your query is bad or you are feeding your query bad information.
|
|
|
|
|
The message is telling you what is wrong; you need to check your binding to see why this column does not exist in the row.
|
|
|
|
|
Hello,
I have UTM coordinates ( North and East) that I would like to transform into pixels for plotting on a form. Can someone advise me how to do this with the transformation feature in C#.
Thanks,
Ron
|
|
|
|
|
I'm currently stuck in a exercise I'm doing and I fear I may be over thinking this, I'm trying to set up the code for a Line class and have two other Line classes each with their own thickness but can't think of anyother way besides g.DrawLine(Pens.Black, 50, 40, 126, 211); and because from how I have my code set up from class with having the DefaultLineThickness it won't cut it.
I've researched but found nothing but simple examples such as the one given and played around different methods. If anyone could help me out it'd be much appreciative. This is my current stand point.
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;
namespace Bicycle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
LineOne l1 = new LineOne(new PointF(50, 40, 126, 211);
l1.setFilledState(false);
l1.setLineColor(Color.Black);
l1.Draw(g);
sRectangle r2 = new sRectangle(new PointF(151, 160));
r2.setFilledState(true);
r2.setLineColor(Color.Green);
r2.setFilledColor(Color.Honeydew);
r2.Draw(g);
sRectangleEmpty r1 = new sRectangleEmpty(new PointF(150, 150));
r1.setFilledState(false);
r1.setLineColor(Color.Blue);
r1.Draw(g);
sCircle c1 = new sCircle(new PointF(180, 130));
c1.setFilledState(true);
c1.setLineColor(Color.Orange);
c1.setFilledColor(Color.Ivory);
c1.Draw(g);
sCircleEmpty c2 = new sCircleEmpty(new PointF(120, 130));
c2.setFilledState(false);
c2.setLineColor(Color.Black);
c2.Draw(g);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Bicycle
{
class Shape
{
private Color DefaultLineColor = Color.Black;
private Color DefaultFillColor = Color.Blue;
private float DefaultLineThickness = 2;
protected bool bOutLine;
protected bool bFilled;
protected Pen pen;
protected Brush brush;
protected PointF location;
private void setDrawingAttributes()
{
pen = new Pen(DefaultLineColor, DefaultLineThickness);
brush = new SolidBrush(DefaultFillColor);
}
private void init()
{
bOutLine = true;
setDrawingAttributes();
}
public Shape()
{
init();
}
public Shape(PointF p)
{
location = p;
init();
}
public Color getFillColor()
{
return (DefaultFillColor);
}
public bool getFilledState()
{
return (bFilled);
}
public Color getLineColor()
{
return (DefaultLineColor);
}
public float getLineThickness()
{
return (DefaultLineThickness);
}
public bool getOutLineState()
{
return (bOutLine);
}
public bool isOutLine()
{
return (bOutLine);
}
public bool isFilled()
{
return (bFilled);
}
public void setFilledColor(Color C)
{
DefaultFillColor = C;
setDrawingAttributes();
}
public void setLineColor(Color C)
{
DefaultLineColor = C;
setDrawingAttributes();
}
public void setLineThickness(float value)
{
DefaultLineThickness = value;
setDrawingAttributes();
}
public void setFilledState(bool value)
{
bFilled = value;
}
public void setOutLineState(bool value)
{
bOutLine = value;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Bicycle
{
class sRectangle
: Shape
{
private bool bCenterPivot = true;
private float width = 20;
private float height = 20;
protected RectangleF rect;
private SizeF size;
private void initRectangle()
{
SizeF offset = new SizeF(size.Width / 2, size.Height / 2);
PointF p1 = PointF.Subtract(location, offset);
rect = new RectangleF(p1, size);
}
private void init()
{
bCenterPivot = true;
initRectangle();
setLineColor(Color.DarkBlue);
}
public sRectangle()
{
size = new SizeF(width, height);
init();
}
public sRectangle(PointF p)
: base(p)
{
size = new SizeF(width, height);
init();
}
public SizeF getSize()
{
return (size);
}
public void setSize(float value)
{
size = new SizeF(value, value);
initRectangle();
}
public void setSize(float W, float H)
{
width = W;
height = H;
size = new SizeF(width, height);
initRectangle();
}
public virtual void Draw(Graphics g)
{
if (bFilled)
g.FillRectangle(brush, rect);
if (bOutLine)
g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Bicycle
{
class sRectangleEmpty
: Shape
{
private bool bCenterPivot = true;
private float width = 100;
private float height = 100;
protected RectangleF rect;
private SizeF size;
private void initRectangle()
{
SizeF offset = new SizeF(size.Width / 2, size.Height / 2);
PointF p1 = PointF.Subtract(location, offset);
rect = new RectangleF(p1, size);
}
private void init()
{
bCenterPivot = true;
initRectangle();
setLineColor(Color.Purple);
}
public sRectangleEmpty()
{
size = new SizeF(width, height);
init();
}
public sRectangleEmpty(PointF p)
: base(p)
{
size = new SizeF(width, height);
init();
}
public SizeF getSize()
{
return (size);
}
public void setSize(float value)
{
size = new SizeF(value, value);
initRectangle();
}
public void setSize(float W, float H)
{
width = W;
height = H;
size = new SizeF(width, height);
initRectangle();
}
public virtual void Draw(Graphics g)
{
if (bOutLine)
g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
}
}
}
|
|
|
|
|
I don't see a definition for LineOne anywhere in the above. Why not edit your question, remove most of the code and just show us the LineOne class and the implementations you want?
|
|
|
|
|
Is there an add on or functionality to insert a partial snippet. I an forever getting half way through a delegate and wanting to insert the tail from a snippet.
dsDashboard.DashboardSelect(VML.PeriodVMStatic.CurrentPeriod.PeriodID, (sErrorMsg, lResult) =>
{
ShowError(sErrorMsg);
xxxList = lResult;
});
I would like to get to the comma in the above statement and there insert the bold tail.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you are using Visual Studio or Visual C# Express, you can create and save code snippets, and later, insert them into your code.
|
|
|
|
|
Code snippets can only be invoked from an empty line (I have about 20 standard ones set up) I am after the ability to invoke it in a partial line.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Code snippets can only be invoked from an empty line
Um.
Not for me...I have a standard snippet to insert a new event: A Simple Code Snippet to Add an Event[^] which works from "evh" [TAB][TAB]. And if I do this:
string hello = evh
And press Tab twice, I get this:
string hello = /// <summary>
/// Event to indicate Description
/// </summary>
public event EventHandler Name;
/// <summary>
/// Called to signal to subscribers that Description
/// </summary>
/// <param name="e"></param>
protected virtual void OnName(EventArgs e)
{
EventHandler eh = Name;
if (eh != null)
{
eh(this, e);
}
} and the cursor is ready to enter the Description.
So can't you do something like this?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
You will see a conceptual framework that I came up with, to the best of my understanding, as I have never worked with the project.
NONMEM (http://www.iconplc.c...roducts/nonmem/) is a software that analysis data that helps provide predictions on a population level, instead of on a single patient. A statistician is responsible to analyse these given data and provide models (sorry, not modules), which are sophisticated mathematical equations, that help predict level of drug concentrations in the blood. Ultimately, we take this data and predict the appropriate doses (output).
So, the statistician will provide the csv file with the required data to be applied to the model. On what bases the model to be chosen, this yet to be figured out. However, I can speculate that the model to be applied to according to its respective product/drug. For example, patient need drug A, so model C corresponds to that drug. Therefore, I want the csv file to be applied to model C because that patient will use drug A.
Does that make sense?
|
|
|
|
|
Member 10759495 wrote: Does that make sense? In a rather vague way, yes. But more importantly, what does it have to do with C#?
|
|
|
|
|
<pre lang="c#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;
public partial class question : System.Web.UI.Page
{
MongoCollection conection;
MongoDatabase database;
string s2;
protected void Page_Load(object sender, EventArgs e)
{
database = new MongoClient("mongodb://avant:avant@127.0.0.1:27017").GetServer().GetDatabase("demo1");
conection = database.GetCollection<ques>("que");
}
class ques
{
public ObjectId id { get; set; }
public string question { get; set; }
public string category { get; set; }
public string answer { get; set; }
public string user { get; set; }
public string name { get; set; }
}
protected void Button1_Click(object sender, EventArgs e)
{
var query = from x in conection.AsQueryable<ques>() where x.category == "c#" select x;
var query1 = from r in conection.AsQueryable<ques>() where r.category == "c lang" select r;
Label[] lbch2 = new Label[100];
HyperLink[] lin = new HyperLink[100];
int k = 0;
if (DropDownList1.Text == "c#")
{
foreach (var var1 in query)
{
lin[k] = new HyperLink();
lbch2[k] = new Label();
lin[k].Text = k + ") " + var1.question;
lbch2[k].Text = "<br><br>";
pan1.Controls.Add(lin[k]);
pan1.Controls.Add(lbch2[k]);
s2 = lin2[k].Text;
lin[k].NavigateUrl = "Default.aspx?t1" + s2;
k++;
}
}
}
}
|
|
|
|
|
So what is your question?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
sorry sir..i want to , when we click on a question just like in this site and same question also display on in another page..
|
|
|
|
|
That's not a question. What have you tried? Where are you stuck?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
So I was discussing this subject with one of my coworkers after he asked me to review some of his code. Our software breaks apart data files, and feeds them to a separate service to be stored in a SQL Server database. His "Record" class has several properties for each of the fields in the client's data file. This particular client's module uses the FileHelpers utility library to read a CSV format, so we're not parsing it manually. Three of the fields are: City, State, ZIP.
Ultimately, we only really care to access the City/State/ZIP as a whole, a formatted string (e.g. Small-Town, USA 12345). With that being said, does it make more sense to loop over a collection of records and call a method like so:
private void SetCityStateZip(Record myRecord)
{
myRecord.CityStateZip = string.Format("{0}, {1} {2}", myRecord.City, myRecord.State, myRecord.Zip);
}
"CityStateZip" is a property in the Record class, referencing a field "_cityStateZip".
Or does it make more sense, instead of creating a whole new field/property, to use a property with a getter that contains the logic as follows:
public string CityStateZip
{
get
{
return string.Format("{0}, {1} {2}", _city, _state, _zip);
}
}
I ask because to me, it makes sense to use the getter with simple logic, as opposed to a separate method. Why? Because CityStateZip is only accessed once for each record when the processing service takes place. The individual City/State/ZIP properties are not used elsewhere.
I figured, for the sake of example, if a data file has 10,000 records, and you call the "SetCityStateZip" method for each, you're setting 10,000 "CityStateZip" properties well before it's even used. There are actually TWO properties like this, so that's 20,000 fields/properties being set when they're each only referenced once in processing. Why assign extra "string" values?
Hope this makes sense. Kind of typed it in a hurry. Just wanting some feedback, as a coworker stated that he believes it's a bad idea to use logic in getters. If he is correct, so be it. But I sometimes enjoy a second/third/fourth/nth. opinion.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Personally, I'd probably go for the property, but...there is a third option which I'd probably prefer: override ToString to return the string version:
public override string ToString()
{
return string.Format("{0}, {1} {2}", _city, _state, _zip);
}
That way, controls such as DataGridView , ComboBox and so forth can also use it.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Which object overrides the ToString() method? I understand the purpose, but the Record class holds far more than just the fields I listed.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
In that case, just stick with the property - it should be more performant since it won't be creating unnecessary strings, and the string will be up-to-date with any changes to the underlying data.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
IMHO, the 2nd option makes much more sense - a get only property that returns the composite information. If the individual components (city , state and zip ) are not read by consumers of Record , they should only be private fields and not exposed as properties.
/ravi
|
|
|
|
|