Showing posts with label visual. Show all posts
Showing posts with label visual. Show all posts

Friday, March 9, 2012

defining command,commandtype and connectionstring for SELECT command is not similar to INS

i am using visual web developer 2005 and SQL 2005 with VB as the code behind

i am usingINSERT command like this

Dim test As New SqlDataSource()
test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString()
test.InsertCommandType = SqlDataSourceCommandType.Text
test.InsertCommand = "INSERT INTO try (roll,name, age, email) VALUES (@.roll,@.name, @.age, @.email) "

test.InsertParameters.Add("roll", TextBox1.Text)

test.InsertParameters.Add("name", TextBox2.Text)
test.InsertParameters.Add("age", TextBox3.Text)
test.InsertParameters.Add("email", TextBox4.Text)
test.Insert()

i am usingUPDATE command like this

Dim test As New SqlDataSource()
test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString()
test.UpdateCommandType = SqlDataSourceCommandType.Text
test.UpdateCommand = "UPDATE try SET name = '" + myname + "' , age = '" + myage + "' , email = '" + myemail + "' WHERE roll 123 "
test.Update()

but i have to use theSELECT command like this which is completely different from INSERT and UPDATE commands

Dim tblData As New Data.DataTable()
Dim conn As New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
Dim Command As New Data.SqlClient.SqlCommand("SELECT * FROM try WHERE age = '100' ", conn)
Dim da As New Data.SqlClient.SqlDataAdapter(Command)
da.Fill(tblData)
conn.Close()

TextBox4.Text = tblData.Rows(1).Item("name").ToString()
TextBox5.Text = tblData.Rows(1).Item("age").ToString()
TextBox6.Text = tblData.Rows(1).Item("email").ToString()


for INSERT and UPDATE commands defining the command,commandtype and connectionstring is same

but for the SELECT command it is completely different. why ?

can i define the command,commandtype and connectionstring for SELECT command similar to INSERT and UPDATE ?

if its possible how to do ?

please help me

Hi you can use:

Insert:

Dim

conAsNew SqlConnection("server=.;database=test;uid=sa")Dim cmdAsNew SqlCommand

con.Open()

cmd.Connection =con

cmd.CommandType =Data.CommandType.Text

cmd.CommandText ="insert into t1(name,birth) values (@.n,@.b)"

cmd.Parameters.Add(

New SqlParameter("@.n", Data.SqlDbType.NVarChar)).Value =TextBox1.Text

cmd.Parameters.Add(

New SqlParameter("@.b", Data.SqlDbType.DateTime)).Value =TextBox2.Text

cmd.ExecuteNonQuery()

con.Close()

Update:

Dim conAsNew SqlConnection("server=.;database=test;uid=sa")

Dim cmdAsNew SqlCommand

con.Open()

cmd.Connection =con

cmd.CommandType =Data.CommandType.Text

cmd.CommandText ="updae t1 setname= @.n , birth= @.b)"

cmd.Parameters.Add(

New SqlParameter("@.n", Data.SqlDbType.NVarChar)).Value =TextBox1.Text

cmd.Parameters.Add(

New SqlParameter("@.b", Data.SqlDbType.DateTime)).Value =TextBox2.Text

cmd.ExecuteNonQuery()

con.Close()

Select:

Dim conAsNew SqlConnection("server=.;database=test;uid=sa")

Dim cmdAsNew SqlCommand

con.Open()

cmd.Connection =con

cmd.CommandType =Data.CommandType.Text

cmd.CommandText ="updae t1 setname= @.n , birth= @.b)"

Dim da As New Data.SqlClient.SqlDataAdapter(Command)
da.Fill(tblData)

con.Close()

|||Sorry the third query is "select .........." not "update ...."

Sunday, February 19, 2012

default value for a parameter to select all

Hello,

I'm using SQLServer 2005 and I build a report in the visual studio.

I need a way to set as default value for a multi-value parameter

its option of 'Select All'.

Thanks, Talia.

Sorry, you cannot pre-select the actual "Select All" entry because it is a client only UI representation item.

The closest you can get is to define the same dataset field as valid value and default value. Then all valid values should be pre-selected.

-- Robert

|||

Thanks.

If somebody has another idea - I'll be happy to hear...

talia.

|||

Well, you could implement your own frontend application that handles the parameter visualization and selection and then use e.g. the new VS 2005 ReportViewer controls (www.gotreportviewer.com) to execute and display the report.

-- Robert

|||

Hey, I think I found the way:

In the Default Values of the parameter, we must choose:

From Query

then, choose the same dataSet and the same ValueField of those

of the parameter - and it select all!

Talia.

|||

Talia,

I'm not sure I understand completely, but I'll offer a workaround and hope that it helps.

It sounds like you have a multi-select parameter with values that do *not* come from a database table. Since the "out of the box" method of defaulting a multi-select parameter to "<Select All>" is to set the default parameter source to a dataset, and you don't have a dataset, you're seeking another solution.

The workaround uses a table variable that you create and populate as part of a dataset definition. You set the Default Values of the multi-select parameter (and the values list as well, if you wish) to that table. Here's how you would do this for a parameter named "StatusCriterion":

Define a dataset named "ValidStatuses" as follows:

-- begin dataset definition

DECLARE @.tblValidStatuses TABLE(
Status VARCHAR(20)
)

INSERT @.tblValidStatuses VALUES('Future Low')
INSERT @.tblValidStatuses VALUES('Future Medium')
INSERT @.tblValidStatuses VALUES('Future High')
INSERT @.tblValidStatuses VALUES('Future Critical')
INSERT @.tblValidStatuses VALUES('Working Medium')
INSERT @.tblValidStatuses VALUES('Working High')
INSERT @.tblValidStatuses VALUES('Working Critical')

SELECT * FROM @.tblValidStatuses

-- end of dataset definition

Then in the Default Values section of the parameter dialogue (bottom of the dialogue) select the "From Query" radio button and choose "ValidStatuses" for the Dataset and "Status" for the Field.

I hope this helps.

-NFox

|||

In SP1, microsoft ruined the select all functionality. I do not know why but they did. I would not invest any time into doing this if you are going to have to redo it all after applying SP1. It is the worst software change I have ever seen.

I digress. Since, you will have to manually create the ALL section. You can just set your default to ="All" or something like that.

|||

In a report based on a Cube (Analysis Services 2005), Is it possible set "All" as default value for a parameter based on dimension

Thank you very much,

Viky V

default value for a parameter to select all

Hello,

I'm using SQLServer 2005 and I build a report in the visual studio.

I need a way to set as default value for a multi-value parameter

its option of 'Select All'.

Thanks, Talia.

Sorry, you cannot pre-select the actual "Select All" entry because it is a client only UI representation item.

The closest you can get is to define the same dataset field as valid value and default value. Then all valid values should be pre-selected.

-- Robert

|||

Thanks.

If somebody has another idea - I'll be happy to hear...

talia.

|||

Well, you could implement your own frontend application that handles the parameter visualization and selection and then use e.g. the new VS 2005 ReportViewer controls (www.gotreportviewer.com) to execute and display the report.

-- Robert

|||

Hey, I think I found the way:

In the Default Values of the parameter, we must choose:

From Query

then, choose the same dataSet and the same ValueField of those

of the parameter - and it select all!

Talia.

|||

Talia,

I'm not sure I understand completely, but I'll offer a workaround and hope that it helps.

It sounds like you have a multi-select parameter with values that do *not* come from a database table. Since the "out of the box" method of defaulting a multi-select parameter to "<Select All>" is to set the default parameter source to a dataset, and you don't have a dataset, you're seeking another solution.

The workaround uses a table variable that you create and populate as part of a dataset definition. You set the Default Values of the multi-select parameter (and the values list as well, if you wish) to that table. Here's how you would do this for a parameter named "StatusCriterion":

Define a dataset named "ValidStatuses" as follows:

-- begin dataset definition

DECLARE @.tblValidStatuses TABLE(
Status VARCHAR(20)
)

INSERT @.tblValidStatuses VALUES('Future Low')
INSERT @.tblValidStatuses VALUES('Future Medium')
INSERT @.tblValidStatuses VALUES('Future High')
INSERT @.tblValidStatuses VALUES('Future Critical')
INSERT @.tblValidStatuses VALUES('Working Medium')
INSERT @.tblValidStatuses VALUES('Working High')
INSERT @.tblValidStatuses VALUES('Working Critical')

SELECT * FROM @.tblValidStatuses

-- end of dataset definition

Then in the Default Values section of the parameter dialogue (bottom of the dialogue) select the "From Query" radio button and choose "ValidStatuses" for the Dataset and "Status" for the Field.

I hope this helps.

-NFox

|||

In SP1, microsoft ruined the select all functionality. I do not know why but they did. I would not invest any time into doing this if you are going to have to redo it all after applying SP1. It is the worst software change I have ever seen.

I digress. Since, you will have to manually create the ALL section. You can just set your default to ="All" or something like that.

|||

In a report based on a Cube (Analysis Services 2005), Is it possible set "All" as default value for a parameter based on dimension

Thank you very much,

Viky V

default value for a parameter to select all

Hello,

I'm using SQLServer 2005 and I build a report in the visual studio.

I need a way to set as default value for a multi-value parameter

its option of 'Select All'.

Thanks, Talia.

Sorry, you cannot pre-select the actual "Select All" entry because it is a client only UI representation item.

The closest you can get is to define the same dataset field as valid value and default value. Then all valid values should be pre-selected.

-- Robert

|||

Thanks.

If somebody has another idea - I'll be happy to hear...

talia.

|||

Well, you could implement your own frontend application that handles the parameter visualization and selection and then use e.g. the new VS 2005 ReportViewer controls (www.gotreportviewer.com) to execute and display the report.

-- Robert

|||

Hey, I think I found the way:

In the Default Values of the parameter, we must choose:

From Query

then, choose the same dataSet and the same ValueField of those

of the parameter - and it select all!

Talia.

|||

Talia,

I'm not sure I understand completely, but I'll offer a workaround and hope that it helps.

It sounds like you have a multi-select parameter with values that do *not* come from a database table. Since the "out of the box" method of defaulting a multi-select parameter to "<Select All>" is to set the default parameter source to a dataset, and you don't have a dataset, you're seeking another solution.

The workaround uses a table variable that you create and populate as part of a dataset definition. You set the Default Values of the multi-select parameter (and the values list as well, if you wish) to that table. Here's how you would do this for a parameter named "StatusCriterion":

Define a dataset named "ValidStatuses" as follows:

-- begin dataset definition

DECLARE @.tblValidStatuses TABLE(
Status VARCHAR(20)
)

INSERT @.tblValidStatuses VALUES('Future Low')
INSERT @.tblValidStatuses VALUES('Future Medium')
INSERT @.tblValidStatuses VALUES('Future High')
INSERT @.tblValidStatuses VALUES('Future Critical')
INSERT @.tblValidStatuses VALUES('Working Medium')
INSERT @.tblValidStatuses VALUES('Working High')
INSERT @.tblValidStatuses VALUES('Working Critical')

SELECT * FROM @.tblValidStatuses

-- end of dataset definition

Then in the Default Values section of the parameter dialogue (bottom of the dialogue) select the "From Query" radio button and choose "ValidStatuses" for the Dataset and "Status" for the Field.

I hope this helps.

-NFox

|||

In SP1, microsoft ruined the select all functionality. I do not know why but they did. I would not invest any time into doing this if you are going to have to redo it all after applying SP1. It is the worst software change I have ever seen.

I digress. Since, you will have to manually create the ALL section. You can just set your default to ="All" or something like that.

|||

In a report based on a Cube (Analysis Services 2005), Is it possible set "All" as default value for a parameter based on dimension

Thank you very much,

Viky V