Saturday, March 31, 2012
System.Drawing.Image.FromFile from URL?
http://www.domain.com/image.jpg instead of c:\image.jpg. ?
thanks!No, but you can use the WebClient or WebRequest classes to bring the
bytes to the local computer and then create the Image obect.
HTH,
Scott
http://www.OdeToCode.com
On 18 Sep 2004 09:23:29 -0700, jcharth@.hotmail.com (Joseph) wrote:
>can i create a system.drawing.Image from a url. using
>http://www.domain.com/image.jpg instead of c:\image.jpg. ?
>thanks!
As scott mentioned, you do not have any method that can directly read the
image from URL.
Use webclient and read it into a byte[] using DownloadData
then you Image class to load it
Regards,
Hermit Dave
(http://hdave.blogspot.com)
"Joseph" <jcharth@.hotmail.com> wrote in message
news:2f2b8b0b.0409180823.2a6f2f18@.posting.google.com...
> can i create a system.drawing.Image from a url. using
> http://www.domain.com/image.jpg instead of c:\image.jpg. ?
> thanks!
System.Drawing.Image.FromFile from URL?
http://www.domain.com/image.jpg instead of c:\image.jpg. ?
thanks!No, but you can use the WebClient or WebRequest classes to bring the
bytes to the local computer and then create the Image obect.
HTH,
--
Scott
http://www.OdeToCode.com
On 18 Sep 2004 09:23:29 -0700, jcharth@.hotmail.com (Joseph) wrote:
>can i create a system.drawing.Image from a url. using
>http://www.domain.com/image.jpg instead of c:\image.jpg. ?
>thanks!
As scott mentioned, you do not have any method that can directly read the
image from URL.
Use webclient and read it into a byte[] using DownloadData
then you Image class to load it
--
Regards,
Hermit Dave
(http://hdave.blogspot.com)
"Joseph" <jcharth@.hotmail.com> wrote in message
news:2f2b8b0b.0409180823.2a6f2f18@.posting.google.c om...
> can i create a system.drawing.Image from a url. using
> http://www.domain.com/image.jpg instead of c:\image.jpg. ?
> thanks!
System.Drawing.Printing
ASP.NET ? Can we direct an output to a printer using these classes ? If not,
what is the alternative ?You can use any namespace with ASP.Net, and you can do anything.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"moko" <nospam-r_chakravarthy@.hotmail.com> wrote in message
news:unQO5kB$DHA.620@.TK2MSFTNGP11.phx.gbl...
> Can the System.Drawing.Print namespace (and it's print methods) be used in
> ASP.NET ? Can we direct an output to a printer using these classes ? If
not,
> what is the alternative ?
I thought "System.Drawing" used GDI+, which in turn is in the context of
Windows, not a web-browser ? Is that not so ?
"Kevin Spencer" <kevin@.takempis.com> wrote in message
news:etWYM3G$DHA.2432@.TK2MSFTNGP11.phx.gbl...
> You can use any namespace with ASP.Net, and you can do anything.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "moko" <nospam-r_chakravarthy@.hotmail.com> wrote in message
> news:unQO5kB$DHA.620@.TK2MSFTNGP11.phx.gbl...
> > Can the System.Drawing.Print namespace (and it's print methods) be used
in
> > ASP.NET ? Can we direct an output to a printer using these classes ? If
> not,
> > what is the alternative ?
No, It is not so. An ASP.Net application is the same as any other
application. For example, you can use GDI+ to create images which you stream
out to a browser on the fly. In any case, the question was about printing,
which uses drawing. Now, I am nt sure that the person who asked understand
that the printing classes will only work on the server side (unless they use
a client-side .Net Windows Form), but there may be a reason why the person
wants their app to do some printing on the server.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"moko" <nospam-r_chakravarthy@.hotmail.com> wrote in message
news:esfXfBH$DHA.2412@.TK2MSFTNGP12.phx.gbl...
> I thought "System.Drawing" used GDI+, which in turn is in the context of
> Windows, not a web-browser ? Is that not so ?
>
> "Kevin Spencer" <kevin@.takempis.com> wrote in message
> news:etWYM3G$DHA.2432@.TK2MSFTNGP11.phx.gbl...
> > You can use any namespace with ASP.Net, and you can do anything.
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Big things are made up
> > of lots of little things.
> > "moko" <nospam-r_chakravarthy@.hotmail.com> wrote in message
> > news:unQO5kB$DHA.620@.TK2MSFTNGP11.phx.gbl...
> > > Can the System.Drawing.Print namespace (and it's print methods) be
used
> in
> > > ASP.NET ? Can we direct an output to a printer using these classes ?
If
> > not,
> > > what is the alternative ?
> > >
System.Drawing.Printing for web form?
I knew that if i want to make some printout in window form, i can use
"System.Drawing.Printing" namespace.
Is it possible to use this namespace in web form in asp.net?
Thank you
Regards,
Angushi
you print form in the server or in the client?
daniel #
"angus" <angus@.angus.com> wrote in message
news:ukXOkZQTEHA.3512@.TK2MSFTNGP12.phx.gbl...
> Dear All,
> I knew that if i want to make some printout in window form, i can use
> "System.Drawing.Printing" namespace.
> Is it possible to use this namespace in web form in asp.net?
> Thank you
> Regards,
> Angus
>
System.Drawing.Printing for web form?
I knew that if i want to make some printout in window form, i can use
"System.Drawing.Printing" namespace.
Is it possible to use this namespace in web form in asp.net?
Thank you
Regards,
Angushi
you print form in the server or in the client?
daniel #
"angus" <angus@.angus.com> wrote in message
news:ukXOkZQTEHA.3512@.TK2MSFTNGP12.phx.gbl...
> Dear All,
> I knew that if i want to make some printout in window form, i can use
> "System.Drawing.Printing" namespace.
> Is it possible to use this namespace in web form in asp.net?
> Thank you
> Regards,
> Angus
System.FormatException: Input String was not in a correct format.
format." while I'm implementing a datagrid and a textbox
What's wrong with it?
Sub Button1_Click(sender As Object, e As EventArgs)
DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
DataGrid1.DataBind()
End Sub
Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
Dim connectionString As String = "server='localhost'; user id='******';
password='******'; database='******'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @dotnet.itags.org.Others)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_others As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_others.ParameterName = "@dotnet.itags.org.Others" dbParam_others.Value = others
dbParam_others.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_others)
Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End FunctionI would guess it is something to do with converting the TextBox1.Text to an
int data type. The textbox could potentially contain a value other than a
numeric value. This would cause this error. Also, MyQueryMethod looks like
it is expecting a value of a string data type. Since you are converting
TextBox1.Text to an int type, this may also cause the error.
-Darrin
"sbox" <s@.b.x> wrote in message
news:%23ibArp48DHA.712@.tk2msftngp13.phx.gbl...
> I've got an error "System.FormatException: Input string was not in a
correct
> format." while I'm implementing a datagrid and a textbox
> What's wrong with it?
> Sub Button1_Click(sender As Object, e As EventArgs)
> DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
> DataGrid1.DataBind()
> End Sub
> Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
> Dim connectionString As String = "server='localhost'; user
id='******';
> password='******'; database='******'"
> Dim dbConnection As System.Data.IDbConnection = New
> System.Data.SqlClient.SqlConnection(connectionStri ng)
> Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
> ([Software].[Others] like @.Others)"
> Dim dbCommand As System.Data.IDbCommand = New
> System.Data.SqlClient.SqlCommand
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
> Dim dbParam_others As System.Data.IDataParameter = New
> System.Data.SqlClient.SqlParameter
> dbParam_others.ParameterName = "@.Others" dbParam_others.Value = others
> dbParam_others.DbType = System.Data.DbType.String
> dbCommand.Parameters.Add(dbParam_others)
> Dim dataAdapter As System.Data.IDbDataAdapter = New
> System.Data.SqlClient.SqlDataAdapter
> dataAdapter.SelectCommand = dbCommand
> Dim dataSet As System.Data.DataSet = New System.Data.DataSet
> dataAdapter.Fill(dataSet)
> Return dataSet
> End Function
You should not have the ' ' in your connection string. Take a look at the
connection strings at
http://www.able-consulting.com/dotn...ManagedProvider
Ben Miller
--
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
"sbox" <s@.b.x> wrote in message
news:%23ibArp48DHA.712@.tk2msftngp13.phx.gbl...
> I've got an error "System.FormatException: Input string was not in a
correct
> format." while I'm implementing a datagrid and a textbox
> What's wrong with it?
> Sub Button1_Click(sender As Object, e As EventArgs)
> DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
> DataGrid1.DataBind()
> End Sub
> Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
> Dim connectionString As String = "server='localhost'; user
id='******';
> password='******'; database='******'"
> Dim dbConnection As System.Data.IDbConnection = New
> System.Data.SqlClient.SqlConnection(connectionStri ng)
> Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
> ([Software].[Others] like @.Others)"
> Dim dbCommand As System.Data.IDbCommand = New
> System.Data.SqlClient.SqlCommand
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
> Dim dbParam_others As System.Data.IDataParameter = New
> System.Data.SqlClient.SqlParameter
> dbParam_others.ParameterName = "@.Others" dbParam_others.Value = others
> dbParam_others.DbType = System.Data.DbType.String
> dbCommand.Parameters.Add(dbParam_others)
> Dim dataAdapter As System.Data.IDbDataAdapter = New
> System.Data.SqlClient.SqlDataAdapter
> dataAdapter.SelectCommand = dbCommand
> Dim dataSet As System.Data.DataSet = New System.Data.DataSet
> dataAdapter.Fill(dataSet)
> Return dataSet
> End Function
System.IndexOutOfRangeException: Index was outside the bounds of the array
Hi i am getting the following error "System.IndexOutOfRangeException: Index was outside the bounds of the array". it is coming from this line of code ;
Line 595: // Build Column Name PartLine 596: strPart1 = strPart1 + "`" + strData[lngIter, 0] + "`,";Line 597:
It may have been caused by the following code;
staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy){
// Array Definitions
//strData(x,0)=ColumnName
//strData(x,1)=ColumnData
You will get this if you use an index that is higher than the number of items in the array. So check if the lngIter is within the index range of the array so you don't pass an index which is higher than the total amount of items in the array.
Hi, i am quite new to programming, so i am unsure if i have declared the arrays properly, however i will show you some code and if you could tell me if you can identify where i have to declare the array.;
The following code is in the page calling up a method;
clsOBJ objDHOC =newclsOBJ();Pmillio.clsOBJ.buildQuery("INSERT","tblProperty", strData, strWhere,"","1","1","strData");
string[,] strData =newstring[11, 2];string[,] strWhere =newstring[11, 3];
strData[0, 0] ="StatutoryDate";strData[0, 1] = txtDate.Text;
The following code is what in the DAL which the one above is referencing;
staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy){
// Array Definitions
//strData(x,0)=ColumnName
//strData(x,1)=ColumnData
// Ucase
strAction = (strAction);
// Dimension
string strSQL;int lngIter;
string strPart1 =null;string strPart2 =null;
System.InvalidCastException
getting this error now System.InvalidCastException: Object must implement
IConvertible. This is showing up on the ExecuteNonQuery line. Below is the
code that I have in my Page_load. I also have no idea of what code I would
use in the Submit_Click event to get the insert to work. Any help would be
appreciated
OleDbConnection conn = new
OleDbConnection("Provider=OraOLEDB.Oracle.1;Persist Security
Info=False;"+"User ID=conference;Password=conf00;Data
Source=ntdrp001.world;");
OleDbCommand command = new OleDbCommand("CONF-REQUEST_INSERT", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("DropDownList1", OleDbType.VarChar).Value =
DropDownList1;
command.Parameters.Add("DropDownList2", OleDbType.VarChar).Value =
DropDownList2;
command.Parameters.Add("txtEStartDate", OleDbType.Date).Value =
txtEStartDate;
command.Parameters.Add("txtEEndDate", OleDbType.Date).Value = txtEEndDate;
command.Parameters.Add("txtEStartTime", OleDbType.Numeric).Value =
txtEStartTime;
command.Parameters.Add("txtEEndTime", OleDbType.Numeric).Value =
txtEEndTime;
command.Parameters.Add("txtEventName", OleDbType.VarChar).Value =
txtEventName;
command.Parameters.Add("txtEventSize", OleDbType.Numeric).Value =
txtEventSize;
command.Parameters.Add("txtSStartDate", OleDbType.Date).Value =
txtSStartDate;
command.Parameters.Add("txtSStartTime", OleDbType.Numeric).Value =
txtSStartTime;
command.Parameters.Add("txtEventDescription", OleDbType.VarChar).Value =
txtEventDescription;
command.Parameters.Add("txtSpecialRequirements", OleDbType.VarChar).Value =
txtSpecialRequirements;
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();Hi, Brian,
The reason is that you directly use the web control objects for the value as
signments. You have to use their properties. like:
command.Parameters.Add("DropDownList1", OleDbType.VarChar).Value = DropDownL
ist1.SelectedItem.Value;
command.Parameters.Add("txtEStartDate", OleDbType.Date).Value = txtEStartDat
e.Text;
Bin Song, MCP
System.InvalidCastException:
I get a System.InvalidCastException on the following code.
ObjtInterestLadder.dblPrinCcyAmt = (double) dsRecs.Tables["DetailData"].Rows[iSub]["Prin_Ccy_Amt"];
Why is this.
When I retrieve the data to a string it is OK
sData = (string) dsRecs.Tables["DetailData"].Rows[iSub]["Prin_Ccy_Amt"].ToString();
have you checked for NULL values?
franklb wrote:
Why is this.
When I retrieve the data to a string it is OK
sData = (string) dsRecs.Tables["DetailData"].Rows[iSub]["Prin_Ccy_Amt"].ToString();
What is it showing when you do that ? If it is null or blank it will show exception.
System.InvalidCastException: Error de QueryInterface para la interfaz GrosConexion._ClaFun
I'km newbie in asp.net. My problem is the subject of this post 'System.InvalidCastException: Error de QueryInterface para la interfaz GrosConexion._ClaFunciones'
I have a dll from a software provider, and i must use your functions from an asp page. My code is (in Page_Load Event of a webform)
Dim RPSGrosVariablesAs GrosVariablesGenererales.ClaVariables
RPSGrosVariables =New GrosVariablesGenererales.ClaVariables
Dim RPSGrosConexionAs GrosConexion.ClaFunciones
RPSGrosConexion =New GrosConexion.ClaFunciones
IfNot IsPostBackThen
gblRutaINI = System.Web.HttpRuntime.AppDomainAppPath & "Prueba.INI"
TextBox1.Text = gblRutaINI
If RPSGrosConexion.AbrirConexion(gblRutaINI, gblMensajeRPS) < 0Then
'Connection fails
Else
'Connection to database ok
EndIf
EndIf
The function AbrirConexion connects to a SQL Server database and returns a short.
If short is less than 0 the connection is OK
I have read very posts in a lot of forums, but my problem is not resolved.
Anyone cab help me? Sorry from my English
Many, many thanx
If RPSGrosConexion.AbrirConexion(gblRutaINI, gblMensajeRPS) < 0Then
to
If RPSGrosConexion.AbrirConexion(textbox1.text, gblMensajeRPS) < 0Then
Also , I would use a try block - something like...
Try
Dim MyShort as Short
MyShort =RPSGrosConexion.AbrirConexion(textbox1.text, gblMensajeRPS)
'do other stuff here with open connection - I'm guessing
Catch exc as exception
Finally
'close connection- if the AbrirConexion leaves it open- I don't know
End Try
HTH
Today, when I turn on my computer, the first time I try the code (without your modification), it runs ok. But the next times i have the same error.
The function AbrirConexion open the connection but don't close it.
And I don't know how to close a connection open by a function.
I don't understand it
Help me, please
Well , we can't guess at it...
check out the Reflector tool here ...http://www.aisto.com/roeder/dotnet/
this will aloow you to "see" inside the DLL - it's methods etc..
use that to read through what functions / methods are available. Youwill run the program and tell it to open the DLL for the component yourare trying to use.
Also, can you get support from the authors of this DLL ?
Hope That Helps
OK, I'll try it
Many thanx
System.InvalidCastException: Specified cast is not
The system worked well until the personnel of the support installed Crystal
Reports Framework 2.0 starting from this moment started to give the mistake below.
Does anybody know how to explain to me the why is happening this mistake?
Server Error in '/SISTEMA' Application.
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 240: //{Line 241: ceReportObject = objReports[1];
Line 242: ceReport = (Report)ceReportObject;
Line 243: ceParameters = ceReport.ReportParameters;Line 244:
Source File:
d:\projetos\sistema\wwwroot\formrelatoriosreservasspever1.aspx.cs
Line: 242
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
sistema.FormRelatoriosReservasSPEVer1.PassarParametros(String
strParam, String strTipoParam, String strNomeParam) in
d:\projetos\sistema\wwwroot\formrelatoriosreservasspever1.aspx.cs:242
sistema.FormRelatoriosReservasSPEVer1.VerRelatorio() in
d:\projetos\sistema\wwwroot\formrelatoriosreservasspever1.aspx.cs:503
sistema.FormRelatoriosReservasSPEVer1.InicializaCrystal() in
d:\projetos\sistema\wwwroot\formrelatoriosreservasspever1.aspx.cs:583
sistema.FormRelatoriosReservasSPEVer1.InitializeComponent() in
d:\projetos\sistema\wwwroot\formrelatoriosreservasspever1.aspx.cs:628
sistema.FormRelatoriosReservasSPEVer1.OnInit(EventArgs e) in
d:\projetos\sistema\wwwroot\formrelatoriosreservasspever1.aspx.cs:619
System.Web.UI.Control.InitRecursive(Control namingContainer)
System.Web.UI.Page.ProcessRequestMain()
Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032
Description
Crystal Enterprise 10, Crystal Reports 10 e VS.Net 2003
Thanks
Set a break point on that line and debug. What type of object is objReports[1], as displayed in the Watch window? and what type of object is ceReportObject, which you are trying to assign it to?System.InvalidCastException: Specified cast is not valid.
I get the this error when i run my code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.DataGrid1.DataSource= this.DataSource();
this.DataGrid1.DataBind();
}
private ICollection DataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
for (int i=0;i<10;i++)
{
DataRow dr = dt.NewRow();
if (i%2==0)
{
dr[0]=1;
}
else
{
dr[0]=0;
}
dt.Rows.Add(dr);
}
DataView dv;
dv = new DataView(dt);
return dv;
}
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int i = e.Item.ItemIndex;
if(i==0)
{
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
}
}
page:
one two
one two
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 56px" runat="server"
Height="216px" Width="448px" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="dll" Runat="server">
<asp:ListItem Value="0">one</asp:ListItem>
<asp:ListItem Value="1">two</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
ch JIt would help if you told us the line #. Is it at:
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
First of all, it looks like you are doing that when ItemIndex == 0
wouldn't that be ur HeaderTemplate in which case cell[0].Controls[0]. really
might not be what you expect. Secondly, you might prefer
e.Item.FindControl("dll") or e.Item.Cells[0].FindContorl("dll") (not sure
which will work, favor the first one if it'll work) over using indexes. It
makes your code more flexible and less likely to break. Sometimes literals
(like spaces and newlines) are converted to controls, so while you might
think it's Controls[0], it might really be Controls[1] 'cuz there was a
newline before it.
It should be pretty easy to step through your code and debug though...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Jimmy" <beffer@.gmail.com> wrote in message
news:eX0b2r$yFHA.2556@.TK2MSFTNGP10.phx.gbl...
> Hi
> I get the this error when i run my code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> this.DataGrid1.DataSource= this.DataSource();
> this.DataGrid1.DataBind();
> }
> private ICollection DataSource()
> {
> DataTable dt = new DataTable();
>
> dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
>
> for (int i=0;i<10;i++)
> {
> DataRow dr = dt.NewRow();
> if (i%2==0)
> {
> dr[0]=1;
>
> }
> else
> {
> dr[0]=0;
>
> }
> dt.Rows.Add(dr);
> }
> DataView dv;
> dv = new DataView(dt);
> return dv;
> }
> private void DataGrid1_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> int i = e.Item.ItemIndex;
> if(i==0)
> {
> ((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
> }
>
> }
>
> page:
>
> one two
> one two
> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
> absolute; TOP: 56px" runat="server"
> Height="216px" Width="448px" AutoGenerateColumns="False">
> <Columns>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:DropDownList ID="dll" Runat="server">
> <asp:ListItem Value="0">one</asp:ListItem>
> <asp:ListItem Value="1">two</asp:ListItem>
> </asp:DropDownList>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> ch J
>
>
>
System.InvalidCastException: Specified cast is not valid.
I get the this error when i run my code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.DataGrid1.DataSource= this.DataSource();
this.DataGrid1.DataBind();
}
private ICollection DataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
for (int i=0;i<10;i++)
{
DataRow dr = dt.NewRow();
if (i%2==0)
{
dr[0]=1;
}
else
{
dr[0]=0;
}
dt.Rows.Add(dr);
}
DataView dv;
dv = new DataView(dt);
return dv;
}
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int i = e.Item.ItemIndex;
if(i==0)
{
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
}
}
page:
one two
one two
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 56px" runat="server"
Height="216px" Width="448px" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="dll" Runat="server">
<asp:ListItem Value="0">one</asp:ListItem>
<asp:ListItem Value="1">two</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid
ch JIt would help if you told us the line #. Is it at:
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
First of all, it looks like you are doing that when ItemIndex == 0
wouldn't that be ur HeaderTemplate in which case cell[0].Controls[0]. really
might not be what you expect. Secondly, you might prefer
e.Item.FindControl("dll") or e.Item.Cells[0].FindContorl("dll") (not sure
which will work, favor the first one if it'll work) over using indexes. It
makes your code more flexible and less likely to break. Sometimes literals
(like spaces and newlines) are converted to controls, so while you might
think it's Controls[0], it might really be Controls[1] 'cuz there was a
newline before it.
It should be pretty easy to step through your code and debug though...
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Jimmy" <beffer@.gmail.com> wrote in message
news:eX0b2r$yFHA.2556@.TK2MSFTNGP10.phx.gbl...
> Hi
> I get the this error when i run my code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> this.DataGrid1.DataSource= this.DataSource();
> this.DataGrid1.DataBind();
> }
> private ICollection DataSource()
> {
> DataTable dt = new DataTable();
>
> dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
>
> for (int i=0;i<10;i++)
> {
> DataRow dr = dt.NewRow();
> if (i%2==0)
> {
> dr[0]=1;
>
> }
> else
> {
> dr[0]=0;
>
> }
> dt.Rows.Add(dr);
> }
> DataView dv;
> dv = new DataView(dt);
> return dv;
> }
> private void DataGrid1_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> int i = e.Item.ItemIndex;
> if(i==0)
> {
> ((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
> }
>
> }
>
> page:
>
> one two
> one two
> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
> absolute; TOP: 56px" runat="server"
> Height="216px" Width="448px" AutoGenerateColumns="False">
> <Columns>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:DropDownList ID="dll" Runat="server">
> <asp:ListItem Value="0">one</asp:ListItem>
> <asp:ListItem Value="1">two</asp:ListItem>
> </asp:DropDownList>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> ch J
>
>
Wednesday, March 28, 2012
System.InvalidOperationException: Connection must be valid and open
I am using this function tu execute updates to a MySql database from a sql
string, but I am getting a System.InvalidOperationException: Connection
must be valid and open.
Database queries work fine, but I cant update the source. Am I missing
something?
Thanks, Alejandro.
public static bool updateSource(string sql)
{
MySqlConnection conn = new MySqlConnection(myConnectionString);
MySqlCommand command = new MySqlCommand(sql,conn);
command.CommandType = CommandType.Text;
try
{
command.ExecuteNonQuery();
return true;
}
catch (Exception)
{return false;}
finally
{
conn.Close();
}Hello Alejandro Penate-Diaz,
Exactly what the error message says... You need to have a valid *and* open
connection.
Try adding conn.Open() before the command.ExecuteNonQuery() method.
Matt Berther
http://www.mattberther.com
> Hi.
> I am using this function tu execute updates to a MySql database from a
> sql string, but I am getting a System.InvalidOperationException:
> Connection must be valid and open.
> Database queries work fine, but I cant update the source. Am I missing
> something?
> Thanks, Alejandro.
> public static bool updateSource(string sql)
> {
> MySqlConnection conn = new MySqlConnection(myConnectionString);
> MySqlCommand command = new MySqlCommand(sql,conn);
> command.CommandType = CommandType.Text;
> try
> {
> command.ExecuteNonQuery();
> return true;
> }
> catch (Exception)
> {return false;}
> finally
> {
> conn.Close();
> }
>
Heyy, thanks!! Problem was that I was like copy-paste and didn't realize
that DataAdapter.Fill actualy does that for me but in this case I have to do
it by myself. ;-)
Thanks a lot!
Alejandro.
"Matt Berther" <mberther@.hotmail.com> wrote in message
news:6852859632389121357049404@.news.microsoft.com...
> Hello Alejandro Penate-Diaz,
> Exactly what the error message says... You need to have a valid *and* open
> connection.
> Try adding conn.Open() before the command.ExecuteNonQuery() method.
> --
> Matt Berther
> http://www.mattberther.com
>
>
System.InvalidOperationException: Collection was modified; enumeration operation may not e
hi all,
i am getting the following error when i am trying to move the ltems form listbox1 to listbox2
"System.InvalidOperationException: Collection was modified; enumeration operation may not execute"
ForEach itemAs ListItemIn Listbox1.ItemsIf item.SelectedAndNot Listbox2.Items.Contains(item)Then
Dim newItemAsNew ListItem(item.Text, item.Value)Listbox2.Items.Add(newItem)
listbox1.Remove(newitem)
EndIf
Next
thanks.
You can't modify the listbox1 item collection while you are iterating over it using "for each". Wait until you add everything to listbox2, and then call Clear() on listbox1.System.InvalidOperationException: Application is restarting
I am getting the following exception in an ASP.NET
application.
Exception Details: System.InvalidOperationException:
Application is restarting.
I have been to the following Support page
http://support.microsoft.com/default.aspx?kbid=312592
and disabled the Realtime monitoring. But, I was not able
to solve the issue.
Any suggestions are greatly appreciated.
Thanks a lot in advance,
Regards
HariHi,
There are vast spectrums of situations that can cause application
restarting. I suggest that you find first the line that causes
application to restart. Start with simple application to check out if
this problem is application specific. If this is the case and other
application doesnt cause recycling you should find the application line
that cause recycling.
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thanks Natty for your prompt reply. Unfortunately I don't
have the real access to the code at the moment and I am
kind of new to ASP.NET. But, I understand the technology
well.
The following is the exception I was getting when this
error occurs: Please have a look if it makes sense. Any
advice from your side is greatly respected.
************************************************** *******
Source=System.Web
Message=Application is
restarting.
StackTrace= at
System.Web.Compilation.CompilationMutex.WaitOne()
+282
at System.Web.Compilation.CompilationLock.GetLock()
+13
at System.Web.UI.TemplateParser.GetParserCacheItem()
+64
at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCac
heItem(String
virtualPath, String inputFile, HttpContext context)
+115
at
System.Web.UI.TemplateControlParser.GetCompiledIns tance
(String
virtualPath, String inputFile, HttpContext context)
+36
at System.Web.UI.PageParser.GetCompiledPageInstance
(String
virtualPath, String inputFile, HttpContext context) +43
at System.Web.UI.PageHandlerFactory.GetHandler
(HttpContext context,
String requestType, String url, String path) +14
at System.Web.HttpApplication.MapHttpHandler
(HttpContext context,
String requestType, String path, String pathTranslated,
Boolean
useAppConfig)
at System.Web.MapHandlerExecutionStep.Execute()
+78
at System.Web.HttpApplication.ExecuteStep
(IExecutionStep step,
Boolean& completedSynchronously) +173
AllException=System.InvalidOperationException:
Application is
restarting.
at System.Web.Compilation.CompilationMutex.WaitOne
()
at System.Web.Compilation.CompilationLock.GetLock
()
at System.Web.UI.TemplateParser.GetParserCacheItem
()
at
System.Web.UI.TemplateControlParser.CompileAndGetP arserCac
heItem(String
virtualPath, String inputFile, HttpContext
context)
at
System.Web.UI.TemplateControlParser.GetCompiledIns tance
(String
virtualPath, String inputFile, HttpContext
context)
at System.Web.UI.PageParser.GetCompiledPageInstance
(String
virtualPath, String inputFile, HttpContext
context)
at System.Web.UI.PageHandlerFactory.GetHandler
(HttpContext context,
String requestType, String url, String
path)
at System.Web.HttpApplication.MapHttpHandler
(HttpContext context,
String requestType, String path, String pathTranslated,
Boolean
useAppConfig)
at System.Web.MapHandlerExecutionStep.Execute
()
at System.Web.HttpApplication.ExecuteStep
(IExecutionStep step,
Boolean&
completedSynchronously)
************************************************** *******
Any advice on this is greatly appreciated
Thanks you very much
Best Regards
Hari
>--Original Message--
>Hi,
>There are vast spectrums of situations that can cause
application
>restarting. I suggest that you find first the line that
causes
>application to restart. Start with simple application to
check out if
>this problem is application specific. If this is the
case and other
>application doesn't cause recycling you should find the
application line
>that cause recycling.
>Natty Gur[MVP]
>blog : http://weblogs.asp.net/ngur
>Mobile: +972-(0)58-888377
>
>*** Sent via Developersdex http://www.developersdex.com
***
>Don't just participate in USENET...get rewarded for it!
>.
Hi,
Nothing special with excaption stuck. it's regular operations that
called while loading a page. try to delete the temporary directory of
your application under
""C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\Tempo rary ASP.NET
Files\YourApplicationName".
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hi,
Nothing special with excaption stuck. it's regular operations that
called while loading a page. try to delete the temporary directory of
your application under
""C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\Tempo rary ASP.NET
Files\YourApplicationName".
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
System.InvalidOperationException: Connection must be valid and open
I am using this function tu execute updates to a MySql database from a sql
string, but I am getting a System.InvalidOperationException: Connection
must be valid and open.
Database queries work fine, but I cant update the source. Am I missing
something?
Thanks, Alejandro.
public static bool updateSource(string sql)
{
MySqlConnection conn = new MySqlConnection(myConnectionString);
MySqlCommand command = new MySqlCommand(sql,conn);
command.CommandType = CommandType.Text;
try
{
command.ExecuteNonQuery();
return true;
}
catch (Exception)
{return false;}
finally
{
conn.Close();
}Hello Alejandro Penate-Diaz,
Exactly what the error message says... You need to have a valid *and* open
connection.
Try adding conn.Open() before the command.ExecuteNonQuery() method.
--
Matt Berther
http://www.mattberther.com
> Hi.
> I am using this function tu execute updates to a MySql database from a
> sql string, but I am getting a System.InvalidOperationException:
> Connection must be valid and open.
> Database queries work fine, but I cant update the source. Am I missing
> something?
> Thanks, Alejandro.
> public static bool updateSource(string sql)
> {
> MySqlConnection conn = new MySqlConnection(myConnectionString);
> MySqlCommand command = new MySqlCommand(sql,conn);
> command.CommandType = CommandType.Text;
> try
> {
> command.ExecuteNonQuery();
> return true;
> }
> catch (Exception)
> {return false;}
> finally
> {
> conn.Close();
> }
Heyy, thanks!! Problem was that I was like copy-paste and didn't realize
that DataAdapter.Fill actualy does that for me but in this case I have to do
it by myself. ;-)
Thanks a lot!
Alejandro.
"Matt Berther" <mberther@.hotmail.com> wrote in message
news:6852859632389121357049404@.news.microsoft.com. ..
> Hello Alejandro Penate-Diaz,
> Exactly what the error message says... You need to have a valid *and* open
> connection.
> Try adding conn.Open() before the command.ExecuteNonQuery() method.
> --
> Matt Berther
> http://www.mattberther.com
>> Hi.
>>
>> I am using this function tu execute updates to a MySql database from a
>> sql string, but I am getting a System.InvalidOperationException:
>> Connection must be valid and open.
>>
>> Database queries work fine, but I cant update the source. Am I missing
>> something?
>>
>> Thanks, Alejandro.
>>
>> public static bool updateSource(string sql)
>>
>> {
>>
>> MySqlConnection conn = new MySqlConnection(myConnectionString);
>>
>> MySqlCommand command = new MySqlCommand(sql,conn);
>>
>> command.CommandType = CommandType.Text;
>>
>> try
>>
>> {
>>
>> command.ExecuteNonQuery();
>>
>> return true;
>>
>> }
>>
>> catch (Exception)
>>
>> {return false;}
>>
>> finally
>>
>> {
>>
>> conn.Close();
>>
>> }
>>
OH Good u found ur Error...
Enjoy
Patrick
"Alejandro Penate-Diaz" wrote:
> Heyy, thanks!! Problem was that I was like copy-paste and didn't realize
> that DataAdapter.Fill actualy does that for me but in this case I have to do
> it by myself. ;-)
> Thanks a lot!
> Alejandro.
> "Matt Berther" <mberther@.hotmail.com> wrote in message
> news:6852859632389121357049404@.news.microsoft.com. ..
> > Hello Alejandro Penate-Diaz,
> > Exactly what the error message says... You need to have a valid *and* open
> > connection.
> > Try adding conn.Open() before the command.ExecuteNonQuery() method.
> > --
> > Matt Berther
> > http://www.mattberther.com
> >> Hi.
> >>
> >> I am using this function tu execute updates to a MySql database from a
> >> sql string, but I am getting a System.InvalidOperationException:
> >> Connection must be valid and open.
> >>
> >> Database queries work fine, but I cant update the source. Am I missing
> >> something?
> >>
> >> Thanks, Alejandro.
> >>
> >> public static bool updateSource(string sql)
> >>
> >> {
> >>
> >> MySqlConnection conn = new MySqlConnection(myConnectionString);
> >>
> >> MySqlCommand command = new MySqlCommand(sql,conn);
> >>
> >> command.CommandType = CommandType.Text;
> >>
> >> try
> >>
> >> {
> >>
> >> command.ExecuteNonQuery();
> >>
> >> return true;
> >>
> >> }
> >>
> >> catch (Exception)
> >>
> >> {return false;}
> >>
> >> finally
> >>
> >> {
> >>
> >> conn.Close();
> >>
> >> }
> >>
>
system.IO
sFile = x:\test\abcd.mdb
if (System.IO.File.Exists(sFile))
//do something
else
//do something else
my code is failing at Exists function. It does not find the file.
X:\ is a mapped drive. X drive has domain account permissions (like
domain\myLoginaccount). also I am runing my web application with default
security as annonymus user called domain\myLoginaccount
Why the Exsits function does not find the file. Am I missing any permissions
here...whats the best mthod to access the files from another machine thru
asp.net
thanks
cheers !I think there are 2 potential hurdles here:
1. does the account running the web page have privileges to access the
share? Be aware that as well as the IIS user and IIS impersonation, you also
have to consider which user the asp.net worker process is running as. This
is quite a complex subject and I'm afraid my knowledge is limited to the
general concept.
2. does the web app actually have the drive mapped? the web server will not
inherit mapped drives from a terminal session so unless you are mapping the
drive from the web app, I don't tihnk it will be there. I would suggest you
try again with a unc path.
Andy
"abcd" <abcd@.abcd.com> wrote in message
news:eXNa%23BpoFHA.3912@.TK2MSFTNGP10.phx.gbl...
> code snippet:-
> sFile = x:\test\abcd.mdb
> if (System.IO.File.Exists(sFile))
> //do something
> else
> //do something else
> my code is failing at Exists function. It does not find the file.
> X:\ is a mapped drive. X drive has domain account permissions (like
> domain\myLoginaccount). also I am runing my web application with default
> security as annonymus user called domain\myLoginaccount
> Why the Exsits function does not find the file. Am I missing any
> permissions here...whats the best mthod to access the files from another
> machine thru asp.net
> thanks
> cheers !
>
system.IO
sFile = x:\test\abcd.mdb
if (System.IO.File.Exists(sFile))
//do something
else
//do something else
my code is failing at Exists function. It does not find the file.
X:\ is a mapped drive. X drive has domain account permissions (like
domain\myLoginaccount). also I am runing my web application with default
security as annonymus user called domain\myLoginaccount
Why the Exsits function does not find the file. Am I missing any permissions
here...whats the best mthod to access the files from another machine thru
asp.net
thanks
cheers !I think there are 2 potential hurdles here:
1. does the account running the web page have privileges to access the
share? Be aware that as well as the IIS user and IIS impersonation, you also
have to consider which user the asp.net worker process is running as. This
is quite a complex subject and I'm afraid my knowledge is limited to the
general concept.
2. does the web app actually have the drive mapped? the web server will not
inherit mapped drives from a terminal session so unless you are mapping the
drive from the web app, I don't tihnk it will be there. I would suggest you
try again with a unc path.
Andy
"abcd" <abcd@.abcd.com> wrote in message
news:eXNa%23BpoFHA.3912@.TK2MSFTNGP10.phx.gbl...
> code snippet:-
> sFile = x:\test\abcd.mdb
> if (System.IO.File.Exists(sFile))
> //do something
> else
> //do something else
> my code is failing at Exists function. It does not find the file.
> X:\ is a mapped drive. X drive has domain account permissions (like
> domain\myLoginaccount). also I am runing my web application with default
> security as annonymus user called domain\myLoginaccount
> Why the Exsits function does not find the file. Am I missing any
> permissions here...whats the best mthod to access the files from another
> machine thru asp.net
> thanks
> cheers !
>
>
System.IO.File class and IP paths?
"\\10.100.100.1\myfolder\test.txt"
When running the aspx file on the server (the server is
also the client) it works, but when using another NT
client it does not work.
The err.description says "Could not find file ..."
System.IO.File.Exists return false here.
But If I manually paste in \\10.100.100.1
\myfolder\test.txt in the IE address field and press "Go"
the file is found.
Strange or not?Hi,
I don't think that the default asp.net user got rights to access network
resources.
Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!