
正文
vb添加net代码,vbnet c#
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何用vb.net查询、添加、删除、修改数据库(需要很详细的代码)?
sQueryString是SQL(增删查改)语句
public
Boolean
ExecSQL(string
sQueryString)
{
SqlConnection
con
=
new
SqlConnection(ConfigurationManager.AppSettings["conStr"]);
con.Open();
SqlCommand
dbCommand
=
new
SqlCommand(sQueryString,
con);
try
{
dbCommand.ExecuteNonQuery();
con.Close();
}
catch
{
con.Close();
return
false;
}
return
true;
}
}
建立一个类,明自己取,然后调用就是了
例如:
类
BC=NEW
类();
STRING
ist="INSERT
INTO
XX(1,2,3)VALUES(A,B,C)";
BC.ExecSQL(ist);
就可以了
相关问答
Q1: 跪求vb.net代码
新建窗口,添加picture控件
利用line()方法画线
line(开始x坐标,开始y坐标)-(结束x坐标,结束y坐标),线的颜色,画线的方式(默认为线,B为矩形无填充,BF为填充的矩形)
For i = 1 To 16
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(255, 0, 0)
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(255, 0, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(0, 255, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(0, 255, 0)
Next i
如果要在窗口上画也可以调用窗口的line方法即form.line()
Q2: VB.NET 注册代码
写两个函数,一个检测是否有重复用户,第二个插入
检测属用户是否存在
private function checkUser(byval uname as string) as boolean
dim sql as string = "select * from [user] where username=" uname
dim cmd as sqlcommand = new sqlcommand(sql,conn)
dim read as sqldatareader = cmd.excutereader
dim result as boolean = read.hasrows
cmd=nothing
return result
end function
新增用户
private sub adduser(byval uname as string,byval password as string)
if checkUser(uname)
messagebox.show("用户已存在")
exit sub
end if
try
dim sql as string = "insert into [user](username,password) values(@uname,@upass)"
dim cmd as sqlcommand = new sqlcommand(sql,conn)
cmd.parameters.add("@uname",sqldbtype.varchar).value=uname
cmd.parameters.add("@upass",sqldbtype.varchar).value=password
cmd.ExecuteNonQuery
cmd=nothing
messagebox.show("用户添加成功!")
catch ex As Exception
messagebox.show("用户添加失败!" + ex.message)
end try
end sub
Q3: 用VB.NET程序编写代码
Delphi代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
购物总价:Integer;
折扣:Extended;
begin
购物总价:=StrToInt(Edit1.Text);
if 购物总价250 then
begin
折扣:=0;
end
else if 购物总价500 then
begin
折扣:=0.05;
end
else if 购物总价1000 then
begin
折扣:=0.075;
end
else if 购物总价2000 then
begin
折扣:=0.1;
end
{
此段的折扣是多少?
else if 购物总价3000 then
begin
折扣:=0.05;
end
}
else if 购物总价=3000 then
begin
折扣:=0.15;
end;
ShowMessage('您享受的折扣是:'+FloatToStr(折扣)
+' 原价:'+IntToStr(购物总价)
+' 折后总价:'+FloatToStr(购物总价*(1-折扣)));
end;
Q4: VB.NET添加按钮代码
⒃谙允景磁サ氖录�刑砑�br /me.backgroundimage=system.drawing.bitmap.fromfile("你的图片文件路径")
命令按钮1.Visable=False'或者命令按钮1.Hide
命令按钮2.Visable=False'或者命令按钮2.Hide
在窗体的Click事件中添加
命令按钮1.Visable=True'或者命令按钮1.show
命令按钮2.Visable=True'或者命令按钮2.show
me.backgroundimage=nothing
在退出按钮的事件中添加
End
2、这里应该还有两个Timer,Timer1和Timer2
在开始按钮的事件中添加
timer1.interval=1000
Timer1.enable=True
timer2.interval=500
timer2.enable=true
在Timer1的Tick事件中添加
label1.text=timeofday
在Timer2的Tick事件中添加
label2.left=label2.left 10
if label2.left
Q5: VB。NET添加代码
我想在窗体上加几个label用来提示错误会更好!!其中用户名为label1,密码为label2,确认密码为label3, 提交为button1,重置为button2,事例:其中名称为Warehouse的SQL数据库里面有一张Administrator1表有用户名和密码两个字段。
'这里是添加的引用
Imports System.Data
Imports System.Data.SqlClient
'提交按钮
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text =







