|
|
Hi,
I have a big problem, I hope you can help me with.
What I want:
A forum where there is 3 columns Subject, AnswersCount, LastAnswer
I have one table with all the data. And two selects functions, where I on the first, get all Subjects for all questions, and on the second select get the Count for all answers on a specific question (with input quiestionId). Both functions works perfect, when I use them seperatly.
But I have to go through all rows in the first selection to find the Count
What shall I do to that?
The code I have now is:
The Repeater, where I want to put all data into:
<asp:repeater id="repDebatIndlaeg" runat="server">
<headertemplate>
Antal indlæg ialt:
<asp:label id="lblIndlaegIalt" runat="server" text="Label">
| |
|
<itemtemplate>
<footertemplate>
| | Emne
| | Antal indlæg
| | Seneste indlæg
|
| | <asp:hyperlink id="lnkEmne" runat="server" text="<%# Eval("Overskrift") %>" navigateurl="<%# "~/Debat.aspx?id=" + Eval("DebatId") %>">
| | <asp:label id="lblAntalIndlaeg" runat="server" text="<%# Eval("DebatNr") %>">
| | <asp:label id="lblSenesteIndlaeg" runat="server" text="<%# Eval("Dato") %>">
|
|
|
The codebehind:
protected void Page_Load(object sender, EventArgs e)
{
DebatApi debatapi = new DebatApi();
if (!IsPostBack)
{
try
{
DataTable Debat = null;
if (debatapi.GetDebat(ref Debat) == Status.Success)
{
int tael = 0;
for (int i = 0; i < Debat.Rows.Count; i++)
{
tael = Convert.ToInt32(Debat.Rows[i]["DebatId"]);
DataTable DebatCount = null;
if (debatapi.GetCountAnswers(tael, ref DebatCount) == Status.Success)
{
}
}
repDebatIndlaeg.DataSource = Debat.DefaultView;
repDebatIndlaeg.DataBind();
}
}
catch
{
}
}
debatapi.Dispose();
}
What shall I put into here so I can write the output into the repeater:
if (debatapi.GetCountAnswers(tael, ref DebatCount) == Status.Success)
{
}
If it was a label outside an repeater, I would make something like:
lblAntalIndlaeg.Text = Convert.ToInt32(GetKontoplanFuld.Rows[i]["DebatNr"]);
But VS cann't finde the lblAntalIndlaeg
I hope someone can help me....Im pretty desperat....
Kind regards,
simsen 
|
|
|
|
|
Hello everyone,
I am using Directshow API in Visual C# enviroment. I am using the following code to toggle Full-Screen. My problem is that when I have the Full-Screen mode, my courser disapears! Can someone tell me how I can have my Courser visiable in the Full-Screen mode?
void ToggleFullScreen()<br />
{<br />
if( videoWin == null )<br />
return;<br />
<br />
int mode;<br />
int hr = videoWin.get_FullScreenMode( out mode );<br />
if( mode == DsHlp.OAFALSE )<br />
{<br />
mode = DsHlp.OATRUE;<br />
hr = videoWin.put_FullScreenMode( mode );<br />
if (hr >= 0)<br />
{<br />
fullScreen = true;<br />
}<br />
}<br />
else<br />
{<br />
mode = DsHlp.OAFALSE;<br />
hr = videoWin.put_FullScreenMode( mode );<br />
if (hr >= 0)<br />
{<br />
fullScreen = false;<br />
}<br />
this.TopMost = true;<br />
this.Refresh();<br />
}
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
1) Before toggling to full screen mode, store a reference to your main window.
2) then handle mouse_move events
3) call Cursor.Draw(..) to draw it on the form as (source code from MSDN Library):
private void DrawCursorsOnForm(Cursor cursor)
{
// If the form's cursor is not the Hand cursor and the
// Current cursor is the Default, Draw the specified
// cursor on the form in normal size and twice normal size.
if(this.Cursor != Cursors.Hand &
Cursor.Current == Cursors.Default)
{
// Draw the cursor stretched.
Graphics graphics = this.CreateGraphics();
Rectangle rectangle = new Rectangle(
new Point(10,10), new Size(cursor.Size.Width * 2,
cursor.Size.Height * 2));
cursor.DrawStretched(graphics, rectangle);
// Draw the cursor in normal size.
rectangle.Location = new Point(
rectangle.Width + rectangle.Location.X,
rectangle.Height + rectangle.Location.Y);
rectangle.Size = cursor.Size;
cursor.Draw(graphics, rectangle);
// Dispose of the cursor.
cursor.Dispose();
}
}
this is the first idea I had after 11 hours of non-stop programming, hope it helps...
|
|
|
|
|
Hi, there!
I can't Update a table in database after a row is deleted in DataSet.
I delete a row, as following:
DataRow[] usersRows;<br />
usersRows = ContactsDataSet.Users.Select("UserName = '" + userName + "'");<br />
foreach (DataRow userRow in usersRows)<br />
userRow.Delete();
and I tried to update the database:
DataSetTableAdapters.UsersTableAdapter usersTableAdapter = new DataSetTableAdapters.UsersTableAdapter();<br />
usersTableAdapter.Update(contactsDataSet.Users);
But the data aren't updated.
Can someone help me?
Thank you in advance.
--
Adrián Córdoba
|
|
|
|
|
aecordoba wrote: usersRows = ContactsDataSet.Users.Select("UserName = '" + userName + "'");
OT: This is dangerous for sql injection attacks...
|
|
|
|
|
First: make sure that the rows are really deleted from the datatable.
Second: What is the deletecommand for the dataadapter?
|
|
|
|
|
The DeleteCommand was automaticaly generated by Visual Studio 2005.
I think the problem is the Deleted status of the rows is in DataSet.
I'm sorry. I'm newbie.
--
Adrián Córdoba
|
|
|
|
|
Don't assume the value came from an untrusted source.
|
|
|
|
|
PIEBALDconsult wrote: Don't assume the value came from an untrusted source.
It's safer to assume it is untrusted...
|
|
|
|
|
|
PIEBALDconsult wrote: No it isn't.
Why not? There are plenty of idiots out there...
|
|
|
|
|
It's never a good idea to trust ANY data comming into your app, even if it IS from a trusted source. The data can be corrupted by the time it reaches your validation code.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
But why assume in this case that the data is "coming into" the application?
He could very well be using
string userName=System.Security.Principal.WindowsIdentity.GetCurrent().Name
or otherwise validating the value.
|
|
|
|
|
True. It doesn't make it 100% valid though. What if the app was run using RunAs, but without the new users profile? Suddenly, the profile path doesn't point to where the userId says it should. Making an assumption like that can also cause problems.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Well, my point is that using a parameter doesn't guarantee safety, only validation of the string will do that.
Even if his snippet said ... "SELECT * FROM Y WHERE X=" + textbox1.Text ..." ... I'd still not assume that proper validation wasn't performed outside the snippet.
|
|
|
|
|
It would appear that you missed this part of my previous post:
... The data can be corrupted by the time it reaches your validation code.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
That's why we have validation code.
Now, if the data gets corrupted after the validation code...
|
|
|
|
|
You can only do so much without resorting to specialized hardware.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Can you tell me how can I select the rows to delete?
I'm sorry. I'm newbie.
--
Adrián Córdoba
|
|
|
|
|
You need to set the Commands.
|
|
|
|
|
The commands were automaticaly generated by Visual Studio 2005 in the moment of insert the DataSet.
--
Adrián Córdoba
|
|
|
|
|
But they're in the original TableAdapter. When you do
DataSetTableAdapters.UsersTableAdapter usersTableAdapter = new DataSetTableAdapters.UsersTableAdapter();
you instantiate a new/uninitialized TableAdapter.
|
|
|
|
|
PIEBALDconsult wrote: You need to set the Commands.
You are right.
Visual Studio 2005 didn't generate the DeleteCommand, seemingly because the Users table in database hasn't a Primary Key.
I added a Primary Key to the table, and when I added this table to the DataSet the DeleteCommand was automaticaly generated.
Thank you very much.
--
Adrián Córdoba
|
|
|
|
|
First off do you have your update command made yet?
I'll I know how to do with DataAdapters is the sql part of them, but if thats what your doing here is an example. It should be kinda the same type of thing.
<cod>
SqlConnection CNN = new SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=true");
SqlDataAdapter DA = new SqlDataAdapter();
DataSet DS = new DataSet();
SqlCommand cmdSelect = CNN.CreateCommand();
cmdSelect.CommandText = "Select CustomerID, ContactName, CompanyName From Customers";
// create an Update command
SqlCommand cmdUpdate = CNN.CreateCommand();
cmdUpdate.CommandText = "Update Customers SET CompanyName=@CompanyName, ContactName=@ContactName WHERE CustomerID=@CustomerID";
cmdUpdate.Parameters.Add("@CompanyName",
SqlDbType.NVarChar, 40, "CompanyName");
cmdUpdate.Parameters.Add("@ContactName",
SqlDbType.NVarChar, 30, "ContactName");
cmdUpdate.Parameters.Add("@CustomerID",
SqlDbType.NChar, 5, "CustomerID");
cmdUpdate.Parameters["@CustomerID"].SourceVersion =
DataRowVersion.Original;
// create an Insert command
SqlCommand cmdInsert = CNN.CreateCommand();
cmdInsert.CommandText =
"Insert into customers (customerid, companyname, contactname) Values (@customerid, @companyname, @contactname)";
cmdInsert.Parameters.Add("@customerid",
SqlDbType.NChar, 5, "customerid");
cmdInsert.Parameters.Add("@companyname",
SqlDbType.NVarChar, 40, "companyname");
cmdInsert.Parameters.Add("@contactname",
SqlDbType.NVarChar, 30, "contactname");
cmdInsert.Parameters["@customerid"].SourceVersion =
DataRowVersion.Original;
// create a Delete command
SqlCommand cmdDelete = CNN.CreateCommand();
cmdDelete.CommandText = "Delete from customers Where customerid = @customerid";
cmdDelete.Parameters.Add("@customerid",
SqlDbType.NChar, 5, "customerid");
cmdDelete.Parameters["@customerid"].SourceVersion =
DataRowVersion.Original;
DA.SelectCommand = cmdSelect;
DA.UpdateCommand = cmdUpdate;
DA.InsertCommand = cmdInsert;
DA.DeleteCommand = cmdDelete;
DA.Fill(DS, "Customers");
//then do whatever you want to with modifying it.
//And then just do update like this
DA.Update(DS, "Customers");
Castro
|
|
|
|