El Valor de Argumento Especificado Para La Función No Es Válido

9
El valor de argumento especificado para la función no es válido. [ Argument # = 1,Name of function(if known) = Sum ] Using cn As New SqlConnection("Data Source=MIPC\sqlexpress;Initial Catalog=MITABLA;Integrated Security=True") cn.Open() Dim query As String = "SELECT SUM(Total) FROM Ventas" Dim cmd As New SqlClient.SqlCommand(query, cn) Label1.Text = CStr(cmd.ExecuteScalar()) End Using Using cn As New SqlConnection("Data Source=MIPC\sqlexpress;Initial Catalog=MITABLA;Integrated Security=True") cn.Open() Dim query As String = "SELECT SUM(Total) FROM Ventas WHERE Fecha = @fecha" Dim cmd As New SqlClient.SqlCommand(query, cn) cmd.Parameters.AddWithValue("@fecha", DatetimePicker.Value.Date) Label1.Text = CStr(cmd.ExecuteScalar()) End Using Using cn As New SqlConnection("connection string") cn.Open() Dim query As String = "SELECT SUM(Largo) As Largo FROM

Transcript of El Valor de Argumento Especificado Para La Función No Es Válido

El valor de argumento especificado para la funcin no es vlido. [ Argument # = 1,Name of function(if known) = Sum ]

Using cn As New SqlConnection("Data Source=MIPC\sqlexpress;Initial Catalog=MITABLA;Integrated Security=True")

cn.Open()

Dim query As String = "SELECT SUM(Total) FROM Ventas"

Dim cmd As New SqlClient.SqlCommand(query, cn)

Label1.Text = CStr(cmd.ExecuteScalar())

End Using

Using cn As New SqlConnection("Data Source=MIPC\sqlexpress;Initial Catalog=MITABLA;Integrated Security=True")

cn.Open()

Dim query As String = "SELECT SUM(Total) FROM Ventas WHERE Fecha = @fecha"

Dim cmd As New SqlClient.SqlCommand(query, cn)cmd.Parameters.AddWithValue("@fecha", DatetimePicker.Value.Date)Label1.Text = CStr(cmd.ExecuteScalar())

End Using

Using cn As New SqlConnection("connection string") cn.Open() Dim query As String = "SELECT SUM(Largo) As Largo FROM NombreTabla" Dim cmd As New SqlCommand(query, cn)

txtLargo.Text = CStr(cmd.ExecuteScalar())

End Using

0

Inicie sesin para votarHola! y eso lo asigno a una variable y esa variable al textbox? como una cosa as?:dim var as doublevar = SELECT SUM(Largo) As Largo FROM NombreTablatextbox1.text = varA eso te refieres Leandro?ehh no debes ejecutar la consulta

Using cn As New SqlConnection("connection string") cn.Open() Dim query As String = "SELECT SUM(Largo) As Largo FROM NombreTabla" Dim cmd As New SqlCommand(query, cn)

txtLargo.Text = CStr(cmd.ExecuteScalar())

End Using

saludos

0

Inicie sesin para votarIf btVer.Enabled = True Then

Using cn As New OleDb.OleDbConnection(strconexion) cn.Open()

Dim query As String = "SELECT SUM(LargoSeccion) As LargoSeccion FROM WLTable" Dim cmd As New OleDb.OleDbCommand(query, cn)

LargoTotal.Text = CStr(cmd.ExecuteScalar()) End Using End If

If Not IsNumeric(txtL.Text) Then MsgBox("Debe ingresar valores numricos") Else If Not IsNumeric(txtB.Text) Then MsgBox("Debe ingresar valores numricos") Else If Not IsNumeric(txtT.Text) Then MsgBox("Debe ingresar valores numricos") Else

If txtDiametro.Text = "1/2" Then var2 = txtResLong.Text + (txtL.Text * 0.3 + txtT.Text * 1.04 + txtB.Text * 0.15) txtResLong.Text = txtResLong.Text + LargoTotal.Text txtResLong.Text = Decimal.Round(var2, 3) btPLoss.Enabled = True End If If txtDiametro.Text = "1" Then var2 = txtResLong.Text + (txtL.Text * 0.6 + txtT.Text * 1.5 + txtB.Text * 0.6) txtResLong.Text = txtResLong.Text + LargoTotal.Text txtResLong.Text = Decimal.Round(var2, 3) btPLoss.Enabled = True End If If txtDiametro.Text = "1 1/2" Then var2 = txtResLong.Text + (txtL.Text * 1.2 + txtT.Text * 2.4 + txtB.Text * 0.6) txtResLong.Text = txtResLong.Text + LargoTotal.Text txtResLong.Text = Decimal.Round(var2, 3) btPLoss.Enabled = True End If If txtDiametro.Text = "2" Then var2 = txtResLong.Text + (txtL.Text * 1.5 + txtT.Text * 3.1 + txtB.Text * 0.9) txtResLong.Text = txtResLong.Text + LargoTotal.Text txtResLong.Text = Decimal.Round(var2, 3) btPLoss.Enabled = True End If If txtDiametro.Text = "2 1/2" Then var2 = txtResLong.Text + (txtL.Text * 1.8 + txtT.Text * 3.7 + txtB.Text * 1.2) txtResLong.Text = txtResLong.Text + LargoTotal.Text txtResLong.Text = Decimal.Round(var2, 3) btPLoss.Enabled = True End If If txtDiametro.Text = "3" Then var2 = txtResLong.Text + (txtL.Text * 2.1 + txtT.Text * 4.6 + txtB.Text * 1.5) txtResLong.Text = txtResLong.Text + LargoTotal.Text txtResLong.Text = Decimal.Round(var2, 3) btPLoss.Enabled = True End If If txtDiametro.Text = "4" Then var2 = txtResLong.Text + (txtL.Text * 3.1 + txtT.Text * 6.1 + txtB.Text * 1.8) txtResLong.Text = txtResLong.Text + LargoTotal.Text txtResLong.Text = Decimal.Round(var2, 3) btPLoss.Enabled = True End If End If End If End If End Sub

UENAS TARDES AMIGOS, SOY NUEVO EN ESTE FORO Y VEO QUE HAY MUCHA GENTE DISPUESTA A AYUDAR A LOS QUE SOMOS PRINCIPIANTES Y ESO SE AGRADECE MUCHO, SI ALGUIEN ME PUDIERA AYUDAR, TENGO ESTA CONSULTA EN MI APLICACION EN VB.NET 2003 A UNA BD EN SQL SERVER 2000:

TryDim cmd3 As SqlClient.SqlCommand = New SqlClient.SqlCommandDim Dr3 As SqlClient.SqlDataReaderDim Qtext3 As String = "Select sum(precio_plato) from detalle whereidorden = '" & idorden.Text & "'"conectar()cmd3.Connection = cnncmd3.CommandText = Qtext3Dr3 = cmd3.ExecuteReaderDr3.Read()TOTAL.Text =CatchMsgBox("EL TOTAL NO SE ENCUENTRA", MsgBoxStyle.Critical)End Try

YA CONFIRME EN EL SQL ANALYZER QUE LA CONSULTA SI ME TIRA EL RESULTADO CORRESPONDIENTE, PERO NO SE QUE PONER PARA JALAR EL RESULTADO AL TEXT DONDE DICE TOTAL.TEXT = NECESITO PONER EL RESULTADO DE LA SUMA Y NO SE COMO YA INTENTE TODO PERO NO ME JALA EL RESULTADO, ALGUIEN CONOCE LA INSTRUCCION O COMO HACER REFERENCIA AL RESULTADO DE LA SUMA???

ESPERO PUEDAN AYUDARME Y MUCHAS GRACIAS!!!!!Avisos GoogleMaestras: MBAEstudialo en la Universidad delPacfico. Inicio: 19 de Junio.www.up.edu.pe/postgrado

#2(permalink) 21/06/2010, 07:39

-rommel_Fecha de Ingreso: junio-2008Ubicacin: LimaMensajes: 361Antigedad: 5 aos, 11 mesesPuntos: 1

Respuesta: Con que instruccion saco el resultado de la suma de una columna?

No recuerdo exactamente la sintaxis, pero debe ser algo de dr3.field(0)... como te dije no recuerdo exactamente...Avisos GoogleLimitar Login Simultaneosen la red Windows con UserLockDescarga gratis - versin de pruebawww.isdecisions.com/userlock

#3(permalink) 21/06/2010, 16:30

raul_mail2005Fecha de Ingreso: junio-2010Mensajes: 12Antigedad: 3 aos, 11 mesesPuntos: 0

Respuesta: Con que instruccion saco el resultado de la suma de una columna?

Gracias por tu respuesta Rommel pero sigue sin funcionar, ahora probe ponerle a la consulta un: AS SUMA, y le pongo dr3.("suma") si lo ejecuta pero no lo muestra, entonces saber porque no jala nada, un amigo me dijo q podia hacerlo con un for sin recurrir a la bd pero no se como se hace, alguna idea?

#4(permalink) 21/06/2010, 16:50

flaviovichFecha de Ingreso: agosto-2005Ubicacin: Lima, PeruMensajes: 2.927Antigedad: 8 aos, 9 mesesPuntos: 36

Respuesta: Con que instruccion saco el resultado de la suma de una columna?

Mira el ejemplo:http://msdn.microsoft.com/es-es/libr...er(VS.80).aspx__________________No repitamos temas, usemos elMotor de busquedasPlantea bien tu problema:Aydanos a ayudarte.

#5(permalink) 22/06/2010, 07:29

-rommel_Fecha de Ingreso: junio-2008Ubicacin: LimaMensajes: 361Antigedad: 5 aos, 11 mesesPuntos: 1

Respuesta: Con que instruccion saco el resultado de la suma de una columna?

yo creo que debes colgar este post en el foro de visual basic .NET y explicarles que hasta ESE PUNTO YA LO TIENES... ahora quieres en contrar la suma... cual es la sintaxis??? algo asi en el FORO de .NETSaludos

#6(permalink) 22/06/2010, 16:48

chusterboyFecha de Ingreso: febrero-2010Mensajes: 35Antigedad: 4 aos, 2 mesesPuntos: 1

Respuesta: Con que instruccion saco el resultado de la suma de una columna?

simplemente debes de tener en cuenta que el reader te extrae aquellos datos que satisfacen la consulta, para ello simplemente pones el nombre del objeto del datareader y entre corchetes pones ya sea el indice de la columna o el nombre de la columna correspondiente en sql, recordar que los datos asignados tambien deben de ser iguales a los de la base de datos.

ejemplo

SqlDataReader lector= statement.ExecuteReader();string cadena=lector[0].toString();ostring cadena=lector["miColumna"].toString();

Claro que antes tienes que hacer una validacion para saber si el reader trae contenido, asi mismo para recorrer todo el reader, para ello normalmente se utiliza un ciclo whilewhile (reader.Read()){string cadena=reader[0].toString();MessageBox.Show(cadena);}

y por ultimo cerrar el reader y listo

reader.Close();

#7(permalink) 08/07/2010, 09:42

raul_mail2005Fecha de Ingreso: junio-2010Mensajes: 12Antigedad: 3 aos, 11 mesesPuntos: 0

Respuesta: Con que instruccion saco el resultado de la suma de una columna?

LO LOGRE RESOLVER LA INSTRUCCION EN NEGRITA ES LA QUE JALA EL DATO DE LA SUMA AL LABEL, GRACIAS A TODOS POR SU AYUDA, AHI LES DEJO EL CODIGO POR SI ALGUIEN TIENE EL MISMO PROBLEMA, NUEVAMENTE GRACIAS.

TryDim MiDataSet As New DataSetDim Comando As SqlClient.SqlCommand = New SqlClient.SqlCommandDim Adaptador As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapterDim objSum As Objectconectar()Comando.CommandText = "Select cantidadcom as CANTIDAD,nombre_plato AS PLATILLO, precio_plato AS PRECIO1, cantidadbeb AS CANTIDAD2,nombre_bebida AS BEBIDA, precio_bebida AS PRECIO2 from detalle where idorden = '" & idorden.Text & "'"Comando.Connection = cnnAdaptador.SelectCommand = ComandoAdaptador.Fill(MiDataSet)DataGrid1.DataSource = MiDataSet.Tables(0)objSum = MiDataSet.Tables(0).Compute("Sum(precio1)", Nothing)TOTAL_COMIDA.Text =(CStr(objSum))Catch ex As ExceptionMsgBox("NO HAY DATOS PARA SUMAR", MsgBoxStyle.Critical)End Try

#8(permalink) 08/07/2010, 17:01

iislasColaboradorFecha de Ingreso: julio-2007Ubicacin: Mexico, D.F.Mensajes: 5.988Antigedad: 6 aos, 10 mesesPuntos: 156

Respuesta: Con que instruccion saco el resultado de la suma de una columna?

Raul

Sabes que si desarrollas completamente en 3 capas, tendras un mejor rendimiento en tus aplicativos, deja del facil mantenimiento que te daran.

CERO CODIGO T-SQL desde tu front.