Showing posts with label plz. Show all posts
Showing posts with label plz. Show all posts

Thursday, February 16, 2012

ASP.NET,Gettting Error in the Program

Hi,

please have look into the code and let me know the solution plz.

string

ProID;try

{

using(SqlConnection conn=new SqlConnection(source))

{

conn.Open();

DataSet ds=

new DataSet();

DDLProject.Items.Clear();

SqlCommand cmd=

new SqlCommand("SP_ProjectSelect",conn);

cmd.CommandType=CommandType.StoredProcedure;

cmd.Parameters.Add("Name",SqlDbType.NChar,30,"@.Name");

cmd.UpdatedRowSource=UpdateRowSource.None;

cmd.Parameters["Name"].Value=DDLProductLine.SelectedItem;

SqlDataReader dr=cmd.ExecuteReader(); ---->>>> Here iam getting Following Error.

while(dr.Read())

{ Response.Write(dr["ID"].ToString());

}

}

}

catch(System.Exception ex)

{

Response.Write(ex);

}

Error:

System.InvalidCastException: Object must implement IConvertible. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteReader() at MIS.UI.ResourceList.DDLProductLine_SelectedIndexChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\dotnet pgms\mis\ui\resourcelist.aspx.cs:line 121

Any suggestion plzz,where went wrong.

Thanks in advance

Regards

Mahesh Reddy

Is it possible your stored procedure "SP_ProjectSelect" is not returning a result set? That's what it sounds like.|||

I think your oder in parameter.add was not correct.

The order should be SQL parameter, DataType, and Input Value.

In your case, it looks like

cmd.Parameters.Add("@.Name",SqlDbType.NChar,30,Name);

Here, "@.Name" is SQL parameter name, Name is the valueable you want to input. You can use "Name" for test. In this case, you will insert "Name" into table.

Also, NChar is not the good datatype for string name. I suggest you change it to VarChar (You need change it in SQL SP too).

Hope it helps

Thursday, February 9, 2012

ASP.NET +Inserting data from xml in SQL Server Database table from ASP.NET

hi

I want to read data from XML file and insert that data from XML file into the Database Table From ASP.NET page.

plz give me the code to do this using DataAdapter.Update(ds)

Hi There,

Below is a simple way to read xml data and update xml datatable to SQLserver database. ( Run a loop if you have multiple table to update )

DataSet dsXML =newDataSet();

dsXML.ReadXml(@."c:\XMLPath\file.xml");

if ( dsXML.Tables.Count > 0 )if ( dsXML.Tables[0].Rows.Count > 0 )

{

// Select table structure to dataadapter

OleDbDataAdapter dataAdapter =newOleDbDataAdapter("SELECT * FROM [" + dsXML.Tables[0].TableName +"] WHERE 1 = 2","YourConnectionString");

// Use dataadapter to update to readed xml data

dataAdapter.Update(dsXML.Tables[0]);

dataAdapter.Dispose();

}

}