Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Monday, March 19, 2012

Datareader insted of dataset Sored Procedure

i m writing a stored procudrue to update my data that is onthertable.and i pass the parameter in my vb code,when i pass the data thatis insert only first record of data but second record insert the eroorwill come is data reader is colsed. now insted of data reade i have touse data set how can i use that and update my data is ontehrtable.?below i written my vb.net2005 code.

Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("Project1connectionString").ToString())
' con.Open()
' Dim ggrnid As String
' Dim acceptqty As String
' Dim itemid As String

' Dim grnid As TextBox = CType(GRNDetailsView.FindControl("fldgrnid"), TextBox)
' ggrnid = grnid.Text

' Dim sWhere As String = grnid.Text
' If (Not String.IsNullOrEmpty(sWhere)) Then
' For Each s As String In sWhere '
' 'Dim iRowIndex As Integer = Convert.ToInt32(s)
' Dim sqldtr As SqlDataReader
' sqlcmd = New SqlCommand
' sqlcmd.Connection = con
' sqlcmd.CommandType = CommandType.Text
' sqlcmd.CommandText = "select acceptqty,itemid fromgrndetail where grnid='" & Trim(ggrnid) & "'"

' datacommand = CommandType.StoredProcedure
' 'datacommand("aaceptqtygrn", con)

' Dim cmd As New SqlCommand("aaceptqtygrn", con)

' sqldtr = sqlcmd.ExecuteReader()

' 'dataset = datacommand.
' 'sqldtr = sqlcmd.ExecuteScalar

' If sqldtr.HasRows = True Then
' While sqldtr.Read()
' acceptqty = sqldtr.Item("acceptqty")
' itemid = sqldtr.Item("itemid")
' cmd.CommandType = CommandType.StoredProcedure
' cmd.Parameters.AddWithValue("@.acceptqty", acceptqty)
' cmd.Parameters.AddWithValue("@.itemid", itemid)
' sqldtr.Close()
' cmd.ExecuteNonQuery()

' End While
' 'sqldtr.Close()
' 'cmd.ExecuteNonQuery()
' 'Next sqldtr.HasRows
' End If
' Next s
' sqldtr.Close()
' con.Close()
' End If
' End If
Catch ex As Exception

MsgBox(ex.Message)

End Try

prajapatiamit2003:

' While sqldtr.Read()
' acceptqty = sqldtr.Item("acceptqty")
' itemid = sqldtr.Item("itemid")
' cmd.CommandType = CommandType.StoredProcedure
' cmd.Parameters.AddWithValue("@.acceptqty", acceptqty)
' cmd.Parameters.AddWithValue("@.itemid", itemid)
' sqldtr.Close()
' cmd.ExecuteNonQuery()

' End While

It looks like you are closing your data reader before exiting you while loop. And you probably do this because your stored proc wont execute while you have the data reader open.

You can either ececute the stored procedure ona different connection, or you can store the results of the reader in some kind of list/array/collection close the reader and then iterate through the collection to execute the sproc.

Because the datareader maintains an open connection to the database you cannot use that connection while the reader is open.

|||But how can i store in array of my data!

Sunday, March 11, 2012

dataflow to excel - Convert numbers stored as text to numbers Excel Cell Error

I'm trying to write data to excel from an ssis component to a excel destination.

Even thought I'm writing numerics, every cell gets this error with a green tag:

Convert numbers stored as text to numbers

Excel Cells were all pre-formated to accounting 2 decimal, and if i manually type the exact data Im sending it formats just fine.

I'm hearing this a common problem -

On another project I was able to find a workaround for the web based version of excel, by writing this to the top of the file:

<style>.text { mso-number-format:\@.; } </style>

is there anything I can pre-set in excel (cells are already formated) or write to my file so that numerics are seen as numerics and not text.

Maybe some setting in my write drivers - using sql servers excel destination.

So close.. Thanks for any help or information.

You received some sugestion on your other thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1392693&SiteID=1

Opening new threads for same problem makes more dificult to help you.

Sunday, February 19, 2012

Database.Create()

I'm looking at using SQL Server SMO to create databases dynamically from a code generator that I'm writing that will use UML class diagrams of business entities as the input metadata.

Is there a sample for using the Microsoft.SqlServer.Management.Smo.Database class, and specifically the Create() method.

When I try a simple call to Create() after merely assigning the database a name, I recieve an inner exception stating:

"You cannot perform operation Create on an object in state Pending."

Any help would be greatly appreciated.

- Doug

There are two ways doing this:


Server svr = new Server(m_yukon);

Database db1, db2;

if ((db1 = svr.Databases["db1"]) != null)
db1.Drop();
if ((db2 = svr.Databases["db2"]) != null)
db2.Drop();

db1 = new Database(svr, "db1");
db1.Create();

db2 = new Database();
db2.Name = "db2";
db2.Parent = svr;
db2.Create();