Vous êtes sur la page 1sur 7

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 votar
Hola! y eso lo asigno a una variable y esa variable al textbox? como una cosa as?:

dim var as double
var = SELECT SUM(Largo) As Largo FROM NombreTabla
textbox1.text = var

A 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 votar
If 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:

Try
Dim cmd3 As SqlClient.SqlCommand = New SqlClient.SqlCommand
Dim Dr3 As SqlClient.SqlDataReader
Dim Qtext3 As String = "Select sum(precio_plato) from detalle where
idorden = '" & idorden.Text & "'"
conectar()
cmd3.Connection = cnn
cmd3.CommandText = Qtext3
Dr3 = cmd3.ExecuteReader
Dr3.Read()
TOTAL.Text =
Catch
MsgBox("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 Google
Maestras: MBA
Estudialo en la Universidad del Pacfico. Inicio: 19 de
Junio. www.up.edu.pe/postgrado
#2 (permalink)
21/06/2010, 07:39

-rommel_

Fecha de Ingreso: junio-2008
Ubicacin: Lima
Mensajes: 361
Antigedad: 5 aos, 11 meses
Puntos: 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 Google
Limitar Login Simultaneos
en la red Windows con UserLock Descarga gratis - versin de
pruebawww.isdecisions.com/userlock
#3 (permalink)
21/06/2010, 16:30
raul_mail2005

Fecha de Ingreso: junio-2010
Mensajes: 12
Antigedad: 3 aos, 11 meses
Puntos: 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

flaviovich

Fecha de Ingreso: agosto-2005
Ubicacin: Lima, Peru
Mensajes: 2.927
Antigedad: 8 aos, 9 meses
Puntos: 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 el Motor de busquedas
Plantea bien tu problema: Aydanos a ayudarte.
#5 (permalink)
22/06/2010, 07:29

-rommel_

Fecha de Ingreso: junio-2008
Ubicacin: Lima
Mensajes: 361
Antigedad: 5 aos, 11 meses
Puntos: 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 .NET
Saludos
#6 (permalink)
22/06/2010, 16:48
chusterboy

Fecha de Ingreso: febrero-2010
Mensajes: 35
Antigedad: 4 aos, 2 meses
Puntos: 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();
o
string 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 while
while (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_mail2005

Fecha de Ingreso: junio-2010
Mensajes: 12
Antigedad: 3 aos, 11 meses
Puntos: 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.

Try
Dim MiDataSet As New DataSet
Dim Comando As SqlClient.SqlCommand = New SqlClient.SqlCommand
Dim Adaptador As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter
Dim objSum As Object
conectar()
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 = cnn
Adaptador.SelectCommand = Comando
Adaptador.Fill(MiDataSet)
DataGrid1.DataSource = MiDataSet.Tables(0)
objSum = MiDataSet.Tables(0).Compute("Sum(precio1)", Nothing)
TOTAL_COMIDA.Text = (CStr(objSum)) Catch ex As Exception
MsgBox("NO HAY DATOS PARA SUMAR", MsgBoxStyle.Critical)
End Try
#8 (permalink)
08/07/2010, 17:01

iislas
Colaborador

Fecha de Ingreso: julio-2007
Ubicacin: Mexico, D.F.
Mensajes: 5.988
Antigedad: 6 aos, 10 meses
Puntos: 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.

Vous aimerez peut-être aussi